Skip to content

Colors wrong when saving ND2 to png #52

@LordKnish

Description

@LordKnish

Hi,
I am using ND2reader to take each color channel (3 in my case) combine and export to a tif. This is an example of what it should look like:
31 5 21 alk ascending concentration_croppedt01xy01 (1)

but instead I get this image which seems like the colors are completely off.
ImageFromND2_hour0 frame0

doing an image analysis and comparison using ImageMagick it seems like my script is just not saving it as 16 bit or combining as 16 bit at all. Any thoughts?

Image from script -> ImageFromND2_hour0.frame0.png PNG 512x512 512x512+0+0 8-bit sRGB 400303B 0.000u 0:00.002
Image From NisElements -> 31.5.21 alk ascending concentration_croppedt01xy01.tif TIFF 512x512 512x512+0+0 16-bit sRGB 1.51925MiB 0.031u 0:00.035

My script:

import time
start_time = time.time()
from nd2reader import ND2Reader, legacy
import cv2
import numpy as np
import pandas as pd 
import matplotlib.pyplot as plt
import os
# Print iterations progress

filelocation = 'Nd2 Conversion\\31.5.21 ALK ascending concentration_Cropped.nd2'
from nd2reader import ND2Reader
with ND2Reader(filelocation) as images:
    l = len(images) * images[0].metadata['fields_of_view'][-1]
    addition = 100 / l
    np.set_printoptions(precision=3)
    numberoffiles = 0
    for x in range(len(images)):
        for fov in images[x].metadata['fields_of_view']:
            c0 = images.parser.get_image_by_attributes(frame_number=x,field_of_view=fov,channel=0,z_level=0,height=512,width=512)
            c1 = images.parser.get_image_by_attributes(frame_number=x,field_of_view=fov,channel=1,z_level=0,height=512,width=512)
            c2 = images.parser.get_image_by_attributes(frame_number=x,field_of_view=fov,channel=2,z_level=0,height=512,width=512)
            no_img = 3
            imagefinal = c0/no_img + c1/no_img + c2/no_img
            plt.imsave("Nd2 Conversion\\ALK Cropped Python\\ImageFromND2_hour" + str(x) + ".frame" + str(fov) + ".png", imagefinal)
            numberoffiles += 1

print("Complete!")
print("--- %s seconds ---" % (time.time() - start_time))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions