Clear Filters
Clear Filters

histogram specialization, imhist error

3 views (last 30 days)
Matthew Worker
Matthew Worker on 25 Sep 2021
Commented: Rena Berman on 13 Dec 2021
%5f)Make CDF of ‘hist_desired’ and ‘hist_xray2’ and store them into ‘cdf_desired’ and ‘cdf_input’
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
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

Answers (1)

Image Analyst
Image Analyst on 25 Sep 2021
imhist() returns two arguments. If you have one then it's just the counts:
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.
Image Analyst
Image Analyst on 25 Sep 2021
You can get the cdf from the counts using cumsum
counts = imhist(grayImage);
theCDF = cumsum(counts);
% Normalize
theCDF = rescale(theCDF, 0, 1);
Image Analyst
Image Analyst on 26 Sep 2021
hist_desired is a structure. Take the semicolon off to see all the variables that are in the structure. You may have stored several variables in the mat file, or maybe just one. Maybe one of the fields is called hist_desired and you can do
storedStructure = load('hist_desired.mat') % No semicolon to see what's in it.
hist_desired = storedStructure.hist_desired

Sign in to comment.




Community Treasure Hunt

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

Start Hunting!