0

Can someone explain why I am getting the following error in my code?

I=imread('lena.jpg');
[M,N]=size(I);
p = zeros(256,3);
for ii=1:256 p(ii,1)=ii-1; end;
p(:,2) = imhist(I);
p (p(:,2)==0,:) = []; % remove zero entries in p
% Calling Shannon procedure, return t1 value and its location in p
[T1,Loc]=Shannon(p);
% Calling Tsallis procedure of Part1
pLow= p(1:Loc,:); T2= Tsallis_Sqrt(pLow);
% Calling Tsallis procedure of Part2
pHigh=p(Loc+1:size(p),:); T3=Tsallis_Sqrt(pHigh);
% Cerate binary matrices f
f=zeros(M,N);
for i=1:M;
for j=1:N;
if ((I(i,j)>= T2)&(I(i,j)<T1))|(I(i,j)>= T3)
f(i,j)=1; end;
end;
end
% Calling EdgeDetector procedure, return edge detection image.
[g]= EdgeDetector(f);
figure;
imshow(g);

I use the Shannon Entropy for find the threshold value. For this I create tree functions:Shannon(p),Tsallis_Sqrt(p),EdgeDetector(f). But I am getting this error in main file. Please help me to solve this error.

??? Error using ==> iptcheckinput
Function IMHIST expected its first input, I or X, to be two-dimensional.

Error in ==> imhist>parse_inputs at 270
iptcheckinput(a, {'double','uint8','logical','uint16','int16','single'}, ...

Error in ==> imhist at 57
[a, n, isScaled, top, map] = parse_inputs(varargin{:});

Error in ==> MainProgram at 6
p(:,2) = imhist(I);

1 Answers1

1

The first argument to imhist(I) has to be a grayscale (intensity) image. Your I is probably an RGB 3-channel image. RGB images have 3 dimensions but the function is expecting a two-dimensional matrix as its input, that's why you get the error.

You may consider converting your image to the grayscale format first

rgbimage = imread('lena.jpg');
I = rgb2gray(RGB);
Alexey
  • 5,898
  • 9
  • 44
  • 81