Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

Fast Histograms without Vision

I need to compute a 3 channel (RGB) histogram on a 1392 x 1039, 7.5fps image.  I do not have the vision toolkit and can't justify buying it just for the histogram function.  I am currently stripping out the 3 channels from the RGB image using color image to array VI, then using the histogram (point-by-point) VI in base package.  To speed it up, I am only using 30 bins and only looking at 1 pixel out of every 10.  It is still way too slow.  Does anyone have an idea of how I can compute a 3 channel histogram as fast as my framerate without purchasing the vision toolkit?
Message 1 of 19
(5,868 Views)
Hi Blitzcraig,

What you are trying to do is a very processor intensive process. The size of your image is really where the problem lies. With that many pixels, the color image to array.vi has to create several very large arrays for each frame, and then those arrays are analyzed for the histogram. All of that conversion takes a lot of processing power and time, and you are trying to do it all 7.5 times a second.

What the Vision software does differently is take the image and store it in memory in a format that can be efficiently processed. So it is not converting the images into RBG arrays as an intermediate step. I hope this information helps!
Nick R
NI
0 Kudos
Message 2 of 19
(5,849 Views)
thanks for the reply nick.

It doesn't seem like the Color Image to Array.vi is the bottleneck in speed.  It is the for loops that I have to run to index the image matrix to obtain the pixel value for R,G, and B.  I have rewritten the histogram function to just increment a pixel value counter for each pixel element which speeds it up quite a bit.  The only way I am able to get close to the speeds I need is to rescale my resolution for a histogram.  I am taking every 20th pixel and using this data for my histogram, which is quite faster, but still not fast enough.  I am running a core2duo CPU, I think I will try to break out the for loops into two parallel threads to process simultaneously on the dual-core processor.  I wish I could just buy the histogram function without paying for the whole vision toolkit.  All I need is a histogram so we can optimize integration times and gain in real-time.
0 Kudos
Message 3 of 19
(5,846 Views)

Can you post some sample code?  It sounds like your code could probably be optimized fairly easily, but it is hard to know without seeing it.

I am guessing some AND operations and shifting operations would quickly isolate the color planes.  Alternately, you could split the high and low words and bytes to get the color planes.  They don't require looping and are pretty fast.  I suspect you could do some quick histograms by isolating the high 5 bits of each color plane (32 buckets), then do a quick summation for the buckets.

Bruce

Bruce Ammons
Ammons Engineering
0 Kudos
Message 4 of 19
(5,839 Views)
Hi Bruce,

What we usually do here at Machine Vision to accelerate this slow process of computing histogram is to take a line on 2 and a column on 2.

It is not an exact statistical process if you have a very sharp image compared to the total hiso but the number of pixel is diveded by 4 so you are 4 times faster in all the steps

Cheers !
Doc-Doc
http://www.machinevision.ch
http://visionindustrielle.ch
Please take time to rate this answer
0 Kudos
Message 5 of 19
(5,830 Views)
Ok, I tried breaking out my for loop into two threads, it was a little bit faster, but not twice as fast as I hoped for.  My cpu is still not maxed out, what gives? 
Using "split numbers.vi" does isolate the channels quickly, but I still have to run thru the for loop for every pixel to create a histogram.  I am dividing the array down to speed up the calculation (in my case, it's the 20th row and the 20th column; 40th row, 40th column, etc), it's now fast enough to get 2-3fps.   I am attaching my histogram calculation vi.  The input to the VI is the isolated channels.
0 Kudos
Message 6 of 19
(5,816 Views)
I was to lazy to install LV8.2 can you save your VI in LV8.01 ?
Doc-Doc
http://www.machinevision.ch
http://visionindustrielle.ch
Please take time to rate this answer
0 Kudos
Message 7 of 19
(5,813 Views)
when you check the "tools - Profile - Performance & Memory" tool in the menu bar, what is the time consuming proces ?
Doc-Doc
http://www.machinevision.ch
http://visionindustrielle.ch
Please take time to rate this answer
0 Kudos
Message 8 of 19
(5,812 Views)
Here's an 8.0 version.
0 Kudos
Message 9 of 19
(5,797 Views)
I came up with a different method of calculating histogram.  Instead of indexing the image array to get pixel values in a for loop, use the for loop to index the value array and sum up all pixel values with that indexed value.  Attached is an example.  I'm not sure if this is faster, but the for loop only has to run 256 times now.  The comparison takes a long time to run on the entire array, so maybe it's not faster. 
0 Kudos
Message 10 of 19
(5,794 Views)