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

3 views (last 30 days)
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);
Ed = imbinarize(Ed);
Ed = imcomplement(Ed);
if ~isequal([N,M], size(Ed))
error('Actual and detected edge image sizes must be same');
a=0.1; % edge shift penalty constant;
fac=length(find((Ea-Ed)==-1)); % False Alarm Count
msc=length(find((Ea-Ed)==1)); % Miss Count
for l=1:Na
for k=1:length(mi)
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;
di=max([n1 n2 m1 m2]);

Answers (2)

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.
% discard the last argument unless you've made sure your inputs are 2D
[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
% but the page geometry [h w] does match
geometryMatches = isequal(imsize(rgbpict,2),imsize(graypict,2))
geometryMatches = logical
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
Image Analyst on 4 Feb 2023
@DGM has the right answer. For more on this, see Steve's blog:

Community Treasure Hunt

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

Start Hunting!