LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

calculating pixel intensity in a black and white image

Solved!
Go to solution

 Hello everyone,

First of all, im new to labview. Now, this question may have been asked before but im not entirely sure. Ok, so i have an avi video that can be broken down to 50 frames. I used imaq threshold  and a for loop to put a threshold in every frame making them black and white. What i want to do is calculate the percentage of area that is highlightened as white. I figured i can do that by calculating the total number of pixels that have an intensity of 1. I know that the black pixels have 0 intensity and i also know the total number of pixels in each frame. I tried using the quantify function but i could not get the desired results. Then i tried using imaq light Meter, but again i could not get the exact number of pixels with intensity of 1, only the mean value and the standar deviation of the pixels. I can probably calculate the area that is intense by using these two values (mean,st.dev.) and simple statistics , i think, but i need more detailed results. Is there a way to get the total number of pixels with intensity of 1 in a black and white frame? sorry if this question has been asked before, i could not find any related one. Sorry for my bad english as well. Awaiting your answers.

Thanks a lot.

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

Hello iskourke,

 

I'm attaching a snippet (a special picture you can drag onto the block diagram and use as code). You will have to wire in the image, and then choose the correct output of "image to array". I have it hooked up to U16 right now but that will be an empty array if your image is not U16.

 

temp.png

Message 2 of 12
(5,728 Views)

Thanks for the reply but i think it is not working. I keep getting the same number of pixels for each frame. The number of pixels is supposed to decrease as the material degrades. I can actually see the white regions decrease but there is no decrease in the pixels>1 indicator.

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

The problemwith gregoryj's code is that it converts the array of booleans to a number, not a count, The value of that number depends heavily on the position of the Values in the array which are True.

 

Once you have the array of pixels of the black and white image (all values either 1 or 0), just use Array Sum to get the number of ones.

 

Lynn

Message 4 of 12
(5,671 Views)

Ah thank you Lynn, I feel so silly now thinking that function would give me the number of "true" elements.

0 Kudos
Message 5 of 12
(5,666 Views)

ok, so i attached lynn's pixel counter to the code, however the pixel sum i get seems really small. So the total number of pixels is 6624000 and of all of them 2515015 should be of intensity >0 (i got the values through vision assistant previously) which is somewhere to 37% of the total pixels. However, the pixel counter gives me really low values (30000) sometimes going even lower to 5000. I have attached my work so far so you can have a look if you want. Sorry for being a bother and thanks for the replies.

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

Can you save for 2014? (File >> Save for previous version...)

 

If you look through your array, do you really only find the values 0 or 1, nothing else?

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

ahh there must be a problem. Everytime i try to save for 2014 labview crashes. To answer your question gregory, yes i saw the array and it was full of 0s and 1s only. Anyways, i figured that if i can track the mean value of intensity from one frame to another, then multiply this mean times 100, i can get the area for each frame.

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

Are you storing the sum as type U16? The max will be something like 65535 and then it will roll back over to zero.

 

Try converting to U32 before taking the sum.

Message 9 of 12
(5,621 Views)

ok, will do

0 Kudos
Message 10 of 12
(5,613 Views)