histogram specialization, imhist error

2 vues (au cours des 30 derniers jours)
Matthew Worker
Matthew Worker le 25 Sep 2021
Commenté : Rena Berman le 13 Déc 2021
%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
  1 commentaire
Rena Berman
Rena Berman le 13 Déc 2021

(Answers Dev) Restored edit

Connectez-vous pour commenter.

Réponses (1)

Image Analyst
Image Analyst le 25 Sep 2021
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.
  2 commentaires
Image Analyst
Image Analyst le 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 le 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

Connectez-vous pour commenter.

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by