🚀 Gen 5 of the leading AI app deployment platform launches October 6. Click for the livestream.

Writing image to mongo db in a right format in dash?

I have an app that writes selected images to MongoDB.

I use dash for this app. And I’m writing an image like this:

def writeMongo(list_of_contents, list_of_names, input1, input2, input3):
    client = pymongo.MongoClient(host=mi_ip, port=port)    
    db = client["imProcessing"]
    schema = db["references"]

    data = [{"refName": str(ref) , "image": str(img), 'code1': input1, 'code2': input2, "code3":input3} for ref, img in zip(list_of_names, list_of_contents)]
    i = schema.insert_many(data)


@app.callback(Output('output-image-upload', 'children'),
            [Input('input1', 'value'),
              Input('input2', 'value'),
              Input('input3', 'value'),
              Input('upload-image', 'contents'),
              Input('saveButton', 'n_clicks')],
              State('upload-image', 'filename'),
              State('upload-image', 'last_modified'))
def update_output(a, b, c, list_of_contents, click_, list_of_names, list_of_dates):
    ifNew = saveButton.isNew(click_)
    if list_of_contents is not None:
        if ifNew:
            if list_of_contents is not None:
               df = pd.DataFrame(data=list_of_contents, index=list_of_names)
               writeMongo(list_of_contents, list_of_names,  a, b, c)
  • Actually this works well. And after this, I can read data well. But I realized that the written image and the read one are not exactly the same. There is some little difference in RGB scores (like 23 instead of 24 or smth).

So actually nobody can understand the difference by eyes, but it is so important for me to study with the same one.

Is there anyone that works with MongoDB and dash before?
Can you give me some advice to handle this problem??

Thanks in advance!!