histogram specialization, imhist error

2 ビュー (過去 30 日間)
Matthew Worker
Matthew Worker 2021 年 9 月 25 日
コメント済み: Rena Berman 2021 年 12 月 13 日
%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
  1 件のコメント
Rena Berman
Rena Berman 2021 年 12 月 13 日

(Answers Dev) Restored edit


回答 (1 件)

Image Analyst
Image Analyst 2021 年 9 月 25 日
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.
  2 件のコメント
Image Analyst
Image Analyst 2021 年 9 月 26 日
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


Community Treasure Hunt

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

Start Hunting!

Translated by