Machine Vision

Showing results for 
Search instead for 
Did you mean: 

open greyscale U16 image problem

Go to solution

Hi, All,

The attached image was taken by a scientific camera and saved as U16 greyscale tiff file. This can be confirmed by using ImageJ, a freeware popular in microscopy field. But When I try to use NI Vision VIs in LV2012 to open it, I found LV always recoganizes it as I16 image and gives a wrong display. Could anybody help em to deal with this problem?





0 Kudos
Message 1 of 12


Thanks for your quick reply.

But it seems you misunderstood my question. It is not I do not know how to convert an I16 2D array to U16 2D array. The file I attached is itself a U16 bit image captured by a scientific camera. But IMAQ (Get Image Info.VI) reads it as an I16 image so it can't be displayed correctly even I creat a U16 image for its loading and display.




0 Kudos
Message 3 of 12
Accepted by topic author Xsword


I think there is something wrong with your tiff file. Because when I save it with LabVIEW in U16, I can reopen it perfectly (see attached file). What program did you use to save it?

(If you use IMAQdx to grab your images, I know there is a pixel signedeness that can affect this. See advanced attributes of your camera under MAX.)

0 Kudos
Message 4 of 12

Sometimes its happened with 16 bit tiff files. The problem with "negative" part of 16 bit range. This also could be Vision issue.

Anyway the given file can be easily opened with the following snippet:






Message 5 of 12

Hi, toto69,

You indentified the reason. I also suspected about the software "ImageJ", by which the tif file was created. Maybe it has a differentdefinition of U16 file from that used by LV. Anyway, I will try to correct this.


Many thanks!




0 Kudos
Message 6 of 12

Hi, Andrey,

Thank you for your reply. I tried your code but found it is not right. It seemed toto69's reply is the right cause of the problem. Anyway, thank you for your help.




0 Kudos
Message 7 of 12

Hi, toto69,

Could you please show me your code of how you saved my attached tif file into correct U16 tiff?





0 Kudos
Message 8 of 12


In fact, I used exactly the same code as Andrey, and simply saved the U16 image obtained with the IMAQ Write File function (in TIF mode).I16toU16.png


0 Kudos
Message 9 of 12

@Xsword wrote:

Hi, Andrey,

Thank you for your reply. I tried your code but found it is not right. It seemed toto69's reply is the right cause of the problem. Anyway, thank you for your help.




Hmm... I think nothing wrong with my code. And nothing wrong with your image. The problem is - how NI recognized that the image should be interpreted as I16 or U16.

Lets me explain. At the first we will create two images with NI software - one is I16 and another one U16.

I will use pretty simple code for generation gradients with full 16 bit range, then save both to 16 bit files and read these files back:




Result of this code is:




So far so good. I16 saved and loaded as I16 and U16 also properly loaded.


Both images can be loaded into ImageJ. Take a note - both interpreted as U16, but appear properly:



then I will save this image as IJ-U16.tif


Now I will try to open this image in NI software with the following snippet:




Result (I added vertical line profile for better understanding what's going wrong):




As you can see - after saving in ImageJ the image wrong interpreted as I16 instead of U16 and converted in bad way.


Now the question is -. how NI recognized is the given tiff image should appear as I16 or U16? Let me compare both NI-I16.tif and NI-U16.tif.




As you can see - both images mostly the same, the only 40 bytes different somewhere at the end. As far as you can know - tiff image contains the image itself and the tags. You can see which tags are inside of your tiff with many utilities. I will use leadtools tiff tag editor (free download


This is NI-I16.tif:



This is NI-U16.tif:



And finally the image saved from ImageJ:




What's different on these three images above?

My first guess was that the tags FillOrder and SampleFormat are responsible for I16/U16 interpretation. For example, "SampleFormat" Tag is present in NI I16 image and missing in NI U16 and ImageJ image. Also FillOrder missing in ImageJ image. After some experiments I have found that these tags are not important. For example, you can remove tag 339 from NI-I16 image, but the image will be still recognized as I16. After half hour play with tags I have seen one more difference in tag 305 ("Software"). In I16 image this tag have length 27 bytes and in in U16 - 29 bytes:


I16 - 27 bytes "National Instruments IMAQ "

U16 - 29 bytes "National Instruments IMAQ   "


As you can see - at the end we have spaces. for I16 - one space and for U16 - three spaces. That's important!


Now I will try to add this tag to the ImageJ file (you can do this with utility from leadtools provided above:




And finally image saved in ImageJ also loaded and appear correctly:





Back to your original image from first post. After adding Tag 305 with value "National Instruments IMAQ   " your image also appear correctly:





Resume. It seems to be that tiff reader from NI recognizes I16/U16 images by presence of the tag 305 in TIff file, which is totally wrong. By default all images where this tag is not present (or have any value different from "National Instruments IMAQ   ") will be recognized as I16 and needs to be converted to U16 programmatically after reading.


Hope this will help for your understanding.




Message 10 of 12