Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

open greyscale U16 image problem

Solved!
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?

 

Thanks!

 

Xsword

0 Kudos
Message 1 of 12
(5,567 Views)

Hi,toto69,

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.

 

best,

Xsword

0 Kudos
Message 3 of 12
(5,558 Views)
Solution
Accepted by topic author Xsword

Hi,

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
(5,551 Views)

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:

 

i16-u16.png

 

Andrey.

 

Message 5 of 12
(5,545 Views)

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!

 

best,

Xsword

0 Kudos
Message 6 of 12
(5,529 Views)

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.

 

best,

Xsword

0 Kudos
Message 7 of 12
(5,527 Views)

Hi, toto69,

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

 

thanks.

 

XSword

0 Kudos
Message 8 of 12
(5,512 Views)

Hi,

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

Regards

0 Kudos
Message 9 of 12
(5,496 Views)

@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.

 

best,

Xsword


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:

 

tiff-test-01.png

 

Result of this code is:

 

tiff-test-02.png

 

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:

 

tiff-test-03.png

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:

 

tiff-test-04.png

 

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

 

tiff-test-05.png

 

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.

 

tiff-test-06.png

 

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 http://www.leadtools.com/rd/v180/LEADTOOLSTIFFTagEditor.exe).

 

This is NI-I16.tif:

tiff-test-07.png

 

This is NI-U16.tif:

tiff-test-08.png

 

And finally the image saved from ImageJ:

 

tiff-test-09.png

 

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:

 

tiff-test-10.png

 

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

 

tiff-test-11.png

 

 

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

 

tiff-test-13.png

 

 

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.

 

Andrey.

 

Message 10 of 12
(5,486 Views)