Open-Science-Tools / nd2reader

Pure Python library for reading NIS Elements ND2 images and metadata
http://www.lighthacking.nl/nd2reader
GNU General Public License v3.0
45 stars 28 forks source link

Plotting ROI's from nd2 files #47

Open ninning opened 3 years ago

ninning commented 3 years ago

Hi!

Im trying to extract from ROI metadata from the nd2 files which i kind of drew like this.

Screen Shot 2021-02-22 at 6 05 00 PM

And after extracting the ROI metadata the output is in a format im not familiar with.

Screen Shot 2021-02-22 at 6 10 59 PM

Is there a way to plot the ROI so that it preserves the overall shape and position? Thanks for the help??

rbnvrw commented 3 years ago

Thank you for your report @ninning! If this shape is stored in the ND2 file, there should of course be some way to implement this. I think that currently, only circular or rectangular ROIs are parsed correctly. This would be a nice improvement but I don't have the time myself to implement it. Of course PRs are very welcome.

kkrucki commented 1 year ago

Was there ever a fix added for this? I tried extracting the x,y values myself but am unsure on the conversion factor from m_vectBasePoints to image pixel units

ninning commented 1 year ago

Was there ever a fix added for this? I tried extracting the x,y values myself but am unsure on the conversion factor from m_vectBasePoints to image pixel units

I dont think so, I just ended up saving the ROI's as a separate binary .tif file with the Nikon software. If you re-load your .nd2 file on the Nikon elements software that you used to take the image, there should be a option to "Save ROI's as..."

kkrucki commented 1 year ago

@rbnvrw @ninning if you add something like the following lines of code to _parse_vect_anim in raw_metadata.py then it will extract the shape in pixels

 x_dict = []
        y_dict = []
        f = animation_dict[six.b('m_sExtrudedShape')]
        for i in range(f[six.b('m_vectBasePoints_Size')]):
            x = f[six.b('m_vectBasePoints_%d' % i)][six.b('x')]
            x = 0.5 *(1+x+animation_dict[six.b('m_dCenterX')]) *self._metadata_parsed["width"]
            x_dict.append(x)
            y = f[six.b('m_vectBasePoints_%d' % i)][six.b('y')]
            y = 0.5  * (1+y+animation_dict[six.b('m_dCenterY')]) *self._metadata_parsed["height"]
            y_dict.append(y)            
        roi_dict["x"] = x_dict
        roi_dict["y"] = y_dict
        return `roi_dict`

I am not the best or most efficient python coder so if you want to add this in a better format by all means add it