MATLAB Answers

histogram specialization, imhist error

38 views (last 30 days)
AZARIA KATHY MOHAMMED
AZARIA KATHY MOHAMMED on 25 Sep 2021 at 12:02
Commented: AZARIA KATHY MOHAMMED on 26 Sep 2021 at 14:39
%5f)Make CDF of ‘hist_desired’ and ‘hist_xray2’ and store them into ‘cdf_desired’ and ‘cdf_input’
x_ray2=imread('x_ray2.png');
hist_xray2=imhist(x_ray);
hist_desired=load('hist_desired.mat');
LUT = zeros(256,1,'double'); % Mapping - casted to double
cdf_input = cumsum(imhist(hist_xray2))/numel(hist_xray2); % cdf of x_ray2 image
cdf_desired = cumsum(imhist(hist_desired))/numel(hist_desired); % cdf of desired image
% 5g)Generate the Look Up Table
for hist_desired=1:256
[~,s] = min(abs(cdf_input(hist_desired)-cdf_desired));
LUT(hist_desired) = s-1; % s-1 here because s goes from 1 to 256 but M(r) ranges from 0 to 255
end
x_ray_HS = LUT((hist_xray2)+1); %5h)Apply the LUT on the ‘x_ray2’;store it into the ‘x_ray_HS’
i keep getting this error: but my image is a grayscale, class double and not rgb
i have also attched th ematlab files
Error using imhist
Expected input number 1, I or X, to be one of these types:
double, uint8, int8, logical, uint16, int16, single, uint32, int32
Instead its type was struct.
Error in imhist>parse_inputs (line 298)
validateattributes(a, {'double','uint8','int8','logical','uint16','int16','single','uint32', 'int32'}, ...
Error in imhist (line 74)
[a, n, isScaled, top, map] = parse_inputs(varargin{:});
Error in Untitled (line 9)
cdf_desired = cumsum(imhist(hist_desired))/numel(hist_desired); % cdf of desired image

Accepted Answer

Image Analyst
Image Analyst on 25 Sep 2021 at 13:16
imhist() returns two arguments. If you have one then it's just the counts:
hist_xray2=imhist(x_ray);
so hist_xray2 is the counts (bin heights). Now, when you do this:
cdf_input = cumsum(imhist(hist_xray2))/numel(hist_xray2);
you're passing in the counts into imhist(). So essentially you're taking the histogram of the counts, not an image, which makes little sense. Rethink your algorithm.
  5 Comments
AZARIA KATHY MOHAMMED
AZARIA KATHY MOHAMMED on 26 Sep 2021 at 14:39
thank you so much! everything works great now. Really learnt alot thank you

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by