Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

Get lower byte from an I16 Image Type

Solved!
Go to solution

Dear Forum,

i get an image from a gige camera (12 bit packed) and Labview create an I16 Image type. so far so good.

But, the next step is: i need an U8 Image type with the lower byte from the I16 image type (camera source)

with the IMAQ cast, it does work correctly. somthing with the shift operator. Have any other an idea or example who,

to get the lower byte from an I16 Image type.need help to understand what do i wrong.

for example:

get to the pixel coordinate (67;267) in the I16 Image Type the grayvalue is 848 (1101010000)

after the casting feature at the same position (67;267) in the U8 Image Type the grayvalue is 255.

i dont understand.

best regards

Alexander Hallmann

Download All
0 Kudos
Message 1 of 6
(3,306 Views)

Dear Alexander,

 

the issue you are facing is caused by the initial 12 bit image depth. This means that your grayscale data will have a maximum pixel value of 4096. If you now try to use the typecast function and assume a 16 bit image, the typecast wont work properly since you actually have a 12 bit image.

 

The workaround for this would be to "manually" change the image depth of your image:

 

1. Use the IMAQ ImagetoArray function and extract the image data as I16.

2. Divide the resulting array by 16 (12bit - 8bit or 4096/255).

3. Use the IMAQ ArraytoImage function to reform your image.

 

The resulting Image will have the U8 Image Type. I hope i could answer your question.

Fabian

Fabian Wehnekamp
Senior Technical Support Engineer
National Instruments
0 Kudos
Message 2 of 6
(3,249 Views)

Thank you for your answer. Ok i understand.One could say that the IMAQ cast does not work properly?!.

Now i use Image to arry and some other tools. see my vi.

0 Kudos
Message 3 of 6
(3,181 Views)

IMAQ Cast should work fine.  When casting 16 bit to 8 bit, you have to decide which bits to drop using the shift parameter.  The shift parameter drops the lowest bits.  In your case, you probably want shift = 4.  This will drop the 4 lowest bits, your image will be the next 8 bits, and the upper 4 bits are eliminated.

 

Usually you want the 8 most significant bits, so you might want to try a shift value of 8.  This will drop the 4 lowest bits of the 12 bit image from the camera (and the four padding zeroes), keeping the 8 most significant bits.  If you know the upper bits will all be zero, you can use a smaller shift value.

 

I think IMAQ Cast will round your value up if the higher pixels are non-zero, so this may not get you what you need.  One solution is to AND the image with the value 255 (or 4095), which will clear the upper bits and prevent rounding.

 

Bruce

Bruce Ammons
Ammons Engineering
0 Kudos
Message 4 of 6
(3,171 Views)

Hi Alex,

 

as Bruce already stated, the IMAQ Cast should work fine. I guess the question is, what do you want to do.

Bruce nicely explained how to drop a certain number of bits from the image and thus decreasing the dynamic range of the image and my explanation pointed out how to convert a 12bit to a 8bit grayscale image and preserving the dynamic range of the image.

 I hope i could clarify the difference between the two methods.

 

Da ich in deinem Vi deutsche Kommentare gefunden habe, hier nochmal die deutsche Version:

 

Grundsätzlich funktioniert die IMAQ Cast Funktion wie beschrieben. Die Frage ist jetzt, was genau die machen möchtest. Wenn du nur die "lower bytes" aus deinem Bild entfernen möchtest, dann kannst du das wie Bruce erklärt hat mit der IMAQ Cast Funktion tun. Das reduziert jedoch die Dynamic Range des Bildes und schneidet einen Teil der Information weg. Die Variante, die ich erklärt habe, erhält die Dynamic Range des Bildes auf kosten der "Auflösung" jedes einzelnen Pixels.

 

Ich hoffe diese Infos helfen dir weiter.

Fabian Wehnekamp
Senior Technical Support Engineer
National Instruments
0 Kudos
Message 5 of 6
(3,163 Views)
Solution
Accepted by topic author HallmannSVS

Es geht darum aus einem Gige Camera Bild, 12 bit oder (16bit), sich die unternen 8 bits anzuschauen und diese unteren acht bits in ein U8 Image type zu speichern.

get the lower byte ( or bits) from an I16 Image type (ok 12bit image type) and put the lower byte into an new Image ( U8 Image Type) .

Thank for your support. my solution: i use Image to Array and swap bytes and AND FF to get the lower byte and then

Arryto Image.

0 Kudos
Message 6 of 6
(3,157 Views)