Local histogram equalization - Using the function 'histeq' in nlfilter/colfilt

Hi Guys,
I need to perform a neighbourhood sliding window operation, that calculates the local histogram of the window, and assigns it to the pixel.
When I use the below code,
g=colfilt(fp,[m n],'sliding',@histeq);
I receive the error as "??? Assignment has more non-singleton rhs dimensions than non-singleton subscripts".
Can someone please advise on this? Thank you for your time.

 Accepted Answer

g=colfilt(fp,[m n],'sliding',@fun);
here fun operates on individual columns(neighbourhood of a pixel) and must return a row vector. but in your case histeq doesnt return a row vector, So, i guess you cant use colfilt, you may use blkproc.
g=blkproc(fp,[m n], @histeq);

More Answers (1)

You probably don't want that anyway. If you're doing a locally adaptive histogram equalization, you want to use adapthisteq(), which is the function meant for doing that.

4 Comments

Yes, but doesn't adapthisteq() work on blocks? I want to perform a sliding window equalization. Is it possible through adapthisteq? I would appreciate if you could suggest any alternate method for this. Thanks!
Yes, but the values in between the tiles are interpolated to give a smooth appearance, so it doesn't look like there are vastly different tiles in your output image. colfilt() is one of those weird, rarely-used functions - most people use blockproc() instead to do this kind of thing. Alternatively you can use nlfilter().
I see. Thank you for your response. Much appreciated!
@Image Analyst: I disagree a bit with your statement that colfilt is "one of those weird, rarely-used functions", as I've used it on several occasions. I generally get much better performance with colfilt() as compared to nlfilter().
For example, I have written implementations of K-nearest-neighbor and bilateral filtering using colfilt(). I'd have to re-write my code to check, but I recall colfilt() working at least an order of magnitude faster. From the documentation:
" Note colfilt can perform operations similar to blockproc and nlfilter, but often executes much faster. "
It's considerably more difficult to write code for colfilt() as compared to the others and not all algorithms are amenable for use with colfilt(). However, there are times when it is quite useful for speeding up algorithms.
Also, thanks for the pointer to adapthisteq. Somehow I've missed this one. I'd actually gone to the trouble of writing my own version of Pizer's AHE algorithm (S. M. Pizer, E. P. Amburn, J. D. Austin, R. Cromartie, A. Geselowitz, T. Greer, B. Terhaarromeny, J. B. Zimmerman, and K. Zuiderveld, "Adaptive Histogram Equalization and Its Variations," Comput Vision Graph 39, 355-368 (1987)), which I believe is pretty much the same thing.
Thanks,
Eric

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!