LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to convert the U8 image to U16 ? or how I use U8 image in U16 for image processing ?

Solved!
Go to solution

Hello,

 

I am working on differential phase contrast imaging project,

Where, I have to generate the differential phase contrast image from two images taken with opposite illumination angle.

Steps to generate the DPC image

1) Add to images .................................................................get image 1

2) Subtract Two images from each other.............................get image 2

3) Divide image 2 / image 1................................................(DPC image) 

 

Equation is = DPC(image) = I(L) - I(R) / I(L) + I(R)

 

I(L) = image taken by illuminating the left half circle.

I(R) = image taken by illuminating the right half circle 

 

Illumination pattern

LEFT half circle(light on LEDS)LEFT half circle(light on LEDS)

 

RIGHT half circle (light on LEDS)RIGHT half circle (light on LEDS)

 

 

So, made VI to do the same task, but I got to know that I can not work with U8 to desire result, so I need to convert the U8 image into U16  or after loading the image ,the pixel values re-format into datatypes with higher bits 

So, if some knows the solution then just let me know.

I will be very helpful to me.

 

I have attached the VI and both images.

Thank you. 

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

Hi,

 

I think what you need is the "IMAQ Cast Image" function from the Vision module.

 

Regards!

ʍolɟɐʇɐp ʞuıɥʇ
0 Kudos
Message 2 of 6
(3,901 Views)

Think a bit about what you are doing.  Your formula may well be correct, but here are some things that bother me:

  • U8 is grey-scale, with 0 being Black and 255 being White (I may have that exactly backwards, but it doesn't change the argument ...).
  • Consider the case of Pixel 1 begin Black, Pixel 2 being White.  The sum of the values is 255, while the difference is also 255 (with the sign depending on Which Comes First), so the ratio is ±1.  Well, +1 is a valid U8 ("almost black"), but -1?  Would this be 255?
  • If the two Pixels have the same value, the formula gives 0, Black.  Can the Formula ever give 255, White?
  • When you extend from 8 to 16 bit numbers, how do you do that?  Do you extend as an Unsigned number, or a signed number?

I think converting to 16-bit may be "solving the wrong problem" ...

 

Bob Schor

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

I extend unsigned number.

As I need to get the phase information from the intensity of the images I need to re-form image into U16 to get out more information and U8 is not suitable to  do image processing while it provides detail between 0 to 255.

 

By subtracting two images taken from the opposite angle of illumination. I have phase gradient information and anyway I have to remove the background information.

 

 

 

I asked to my professor and he asked me to do '' 

After loading the images, the pixel values should be re-formatted into datatypes with higher bits , e.g., double. UNIT8 is 8bit, not suitable for computation.''

 

what I am doing is,  if I do summation of two images I will have images like sown below (I(T) + I (B)) and when I use that above equation I will have dpc image like shown below.  

dpccc.JPG

0 Kudos
Message 4 of 6
(3,865 Views)
Solution
Accepted by topic author @mi

OK, that's pretty helpful.  So let me reformulate the problem slightly.

 

There are two problems with U8 -- one is the "unsigned" aspect which raises a problem with a Subtract operation (since one less than 0, a "little bit darker than black", gives 255, "white", which doesn't make sense).  The other is the fact that Integers don't do well with division.  What numeric format supports subtraction and division?  Floats.

 

So let's remap U8 to a Float, and see what makes sense.  Let's start by saying "Black is 0, White is 1".  Let's look at (A - B) / (A + B).  Here's a little exercise you can do (I just did it, took me less than 5 minutes) -- generate two arrays of 11 numbers from 0, 0.1, ..., 1.0, and call them A and B.  Create the 2D array of A-B / A+B and look at the results.  You'll find that except when A and B are both 0, all of the numbers range from +1 to -1.  I'm not sure it would make sense, but taking Absolute Values gets us back to a 0 .. 1 range (except when A and B are both zero).

 

So armed with this, I went back to your code and found one "silly mistake" (look at the Division operation -- you are dividing A+B by A-B, oops ...).  Look at the Images you are creating using IMAQ Create -- by default, they are all U8.  So make them all Grayscale (SGL).  Fix the earlier image.  Also run the Error Line between the IMAQ functions, so if there is an Error (like Division by 0) somewhere, you'll know about it.  It will (perhaps) also help you to keep your Block Diagram more tidy.

 

Once you've cleaned up the code (clean it up first, please), try running it.  You might be pleasantly surprised.  [I'll note that your Left and Right images seem a little too similar to each other ... maybe you can get a better Image pair].

 

Bob Schor

 

 

Message 5 of 6
(3,854 Views)

Finally I got the Differential Phase Contrast Image by following the steps you suggested.

Thank you very much for helping me solve my problem and clearing out the my doubts.

 

 

I got the solution but still this I do have idea what you trying to say in below quotes. 

 

'' generate two arrays of 11 numbers from 0, 0.1, ..., 1.0, and call them A and B.  Create the 2D array of A-B / A+B and look at the results.  You'll find that except when A and B are both 0, all of the numbers range from +1 to -1.  I'm not sure it would make sense, but taking Absolute Values gets us back to a 0 .. 1 range (except when A and B are both zero)''

 

As I am working to get the phase details from the two images taken at opposite angle of illumination , so both images will look a like same, but the intensity information will be different and I use intensity details to recover the phase information.

 

Thank you very much again.

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