The program showing "Error using - Matrix dimensions must agree. out = im2double(a) - im2double(d);"

a=imread('Whiteimage.jpg');
b=imread('vegetableimage.jpg');
c=rgb2gray(b);
d=im2bw(c);
out=im2double(a)-im2double(d);
se=strel('disk',6);
frameout=imdilate(out,se);
[L,n]=bwlabel(frameout,8);
s=regionprops(L,'Area','Centroid','BoundingBox','Perimeter');
imshow(b)

3 Kommentare

Jan
Jan am 12 Dez. 2018
Bearbeitet: Jan am 12 Dez. 2018
I've formatted your code tody. Please learn how to use the formatting tools in the forum.
how can i learn use of the formatting tools?
Jan
Jan am 17 Dez. 2018
Bearbeitet: Jan am 17 Dez. 2018
Do you see the bar with icons directly on top of the field to type or edit your messages in the forum? On the right hand you find a small question mark. Click on it to get the help page (link).
I'm surprised that this is not trivial.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

The error message is clear: a and d have different sizes. While d is a 2D matrix, a is most likely an RGB array with 3 dimensions. Check this using the debugger. Type this in the command window:
dbstop if error
Run the code again. When it stops at the error, check the sizes:
size(a)
size(d)

1 Kommentar

Actually, if the two images are the same width and height, it shouldn't matter if one is greyscale and the other RGB, at least on versions >= R2016b. With implicit expansion, the grey image would be subtracted from each colour channel.
Therefore, either the OP is using an old version of matlab (in which case use bsxfun for the subtraction) or the images are completely different size (in which case, maybe they should be resized to a common size?)

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Scope Variables and Generate Names finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 12 Dez. 2018

Kommentiert:

am 17 Dez. 2018

Community Treasure Hunt

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

Start Hunting!

Translated by