i have written code for histogram am getting this error ?? Input argument "I" is undefined.

3 views (last 30 days)
% takes a 2D array (or image) I as input and returns
% an image of the same type that has undergone histogram
% equalization using n bins and has a range of outputs
% that spans the range between min and max.
% O - output histogram equalized image
function [O] = histoeq(I, n, min, max)
[h,bins] = histogram(I, n, min, max);
O = zeros(size(I));
imcdf = 0;
for i=1:n-1
index = ((I>=bins(i)) .* (I<bins(i+1))) == 1;
imcdf = imcdf + h(i);
O(index) = max*imcdf;
end
% handle the last bin:
index = ((I>=bins(n)) .* (I<=max)) == 1;
imcdf = imcdf + h(n);
O(index) = max*imcdf;
O = uint8(O); % for imshow...

Answers (2)

Walter Roberson
Walter Roberson on 8 Dec 2013
Exactly how are you starting the function executing? When you have a function with parameters, you cannot start it by pressing an F* key or clicking on a menu item: instead you need to go down to the command line and type in the command indicating the parameters you are passing in.

Image Analyst
Image Analyst on 8 Dec 2013
The Image Processing Toolbox already has this useless function. It's called histeq(). Why don't you just use that? Like I said, it's pretty much useless for a number of reasons but it's there. For educational purposes I guess. Kind of like Otsu thresholding done by graythresh() - usually useless but it's simple and easy and taught about in schools so they put it in. I never use it. There's a locally adaptive histogram equalization version that isn't useless and sometimes finds use for background correction. It's called adapthisteq().

Community Treasure Hunt

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

Start Hunting!