# Error using actual and detected edge image sizes must be same error.

3 views (last 30 days)
Alan George on 3 Feb 2023
Edited: DGM on 4 Feb 2023
function F = pratt(Ea,Ed)
% Function EDPM : Edge detector performance measure function.
% Calculates for a given edge image the false alarm
% count, miss count and figure of merit (F) values.
%
%
% Input(s)... Ea : Actual edge image
% Ed : Detected edge image.
%
% Output(s).. fac: False alarm count
% msc: miss count
% F : Figure of merit
Ea = imbinarize(Ea);
Ea = imcomplement(Ea);
Ea=double(Ea);
Ed = imbinarize(Ed);
Ed = imcomplement(Ed);
Ed=double(Ed);
[N,M]=size(Ea);
if ~isequal([N,M], size(Ed))
error('Actual and detected edge image sizes must be same');
end;
a=0.1; % edge shift penalty constant;
fac=length(find((Ea-Ed)==-1)); % False Alarm Count
msc=length(find((Ea-Ed)==1)); % Miss Count
Na=sum(sum(Ea));Nd=sum(sum(Ed));
c=1/max(Na,Nd);
[ia,ja]=find(Ea==1);
for l=1:Na
Aes(l)=Ed(ia(l),ja(l));
end;
mi=ia(find(Aes==0));
mj=ja(find(Aes==0));
F=c*sum(Aes);
for k=1:length(mi)
n1=0;n2=0;m1=0;m2=0;
while sum(sum(Ed(mi(k)-n1:mi(k)+n2,mj(k)-m1:mj(k)+m2)))<1
if mi(k)-n1>1 n1=n1+1;end;
if mi(k)+n2<N n2=n2+1;end;
if mj(k)-m1>1 m1=m1+1;end;
if mj(k)+m2<M m2=m2+1;end;
end;
di=max([n1 n2 m1 m2]);
F=F+c/(1+a*di^2);
end;

DGM on 4 Feb 2023
Edited: DGM on 4 Feb 2023
Your inputs are JPG. Most JPGs will not be single-channel. On one side of that equality test, this is what happens:
rgbpict = imread('llama.jpg'); % a color image
% this is the actual size of the image
sz = size(rgbpict)
sz = 1×3
876 1314 3
% this is what you get when you don't use size() carefully
[h w] = size(rgbpict)
h = 876
w = 3942
When you call size() with K scalar outputs, the Kth (last) output is not the size of the Kth dimension. It's the product of the sizes of the Kth dimension and the sizes of all trailing dimensions. Hence, in this example, it's 1314*3. This is documented, but commonly overlooked behavior. If you do not ensure that your inputs have the number of dimensions you think they do, you must always discard the last argument.
[h,w,~] = size(rgbpict);
Similarly, consider the other side of the equality test. When you call size() with vector outputs, the length of the vectors are controlled by the dimensionality of the array. If you're not controlling that, then there's no reason to assume that the output is a 2-element vector. If the size of the vectors mismatch, isequal() will return false, regardless of what the page geometry is.
Normally, I just avoid size().
rgbpict = imread('llama.jpg'); % a color image
graypict = im2gray(rgbpict); % a single-channel image
% the sizes [h w ch] don't match
sizeMatches = isequal(imsize(rgbpict),imsize(graypict))
sizeMatches = logical
0
% but the page geometry [h w] does match
geometryMatches = isequal(imsize(rgbpict,2),imsize(graypict,2))
geometryMatches = logical
1
Ultimately, I doubt you intend to actually be processing RGB images at all. If that's the case, use rgb2gray() or im2gray() to convert them before binarizing.

Image Analyst on 4 Feb 2023
@DGM has the right answer. For more on this, see Steve's blog:

### Categories

Find more on Object Analysis in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!