Info
This question is closed. Reopen it to edit or answer.
This code isn't working. How do I change the datatype of the image B such that it is also 128*128, the error is :
1 view (last 30 days)
Show older comments
Error using .* Matrix dimensions must agree.
Error in fy (line 33) circle_image = double(B).* circleMat;
A=imread('search.jpg');
figure,imshow(A); title('Original Image');
%Convert the Image to binary
B=im2bw(A);
%Fill the holes
C=imfill(B,'holes');
%Label the connected components
[Label,Total]=bwlabel(C,8);
%Rectangle containing the region
Sdata=regionprops(Label,'BoundingBox');
%Crop all the objects
for i=1:1%Total
Img=imcrop(A,Sdata(i).BoundingBox);
Name=strcat('Object Number:',num2str(i));
imwrite(Img,'i.jpg');
B=padarray(Img,[10 10]);
B=imresize(B,[128 128]);
figure,imshow(B); title(Name);
end
rows = 128;
cols = 128;
radius=64;
center = [64 64];
for radius=1:64
[xMat,yMat] = meshgrid(1:cols,1:rows);
distFromCenter = sqrt((xMat-center(1)).^2 + (yMat-center(2)).^2);
circleMat = distFromCenter<=radius;
circle_image = double(B).* circleMat;
ne(radius) = length(find(circle_image > 0))
end
It shows that the dimensions of B are 128*128*3uint8 and that of circleMat is 128*128 logical.
0 Comments
Answers (1)
Walter Roberson
on 24 Mar 2018
At that point, B is something that has been cropped out of the color image A and resized.
Your code tries to count nonzero pixels within a range of radii. You need to decide whether for color images whether you want to count the pixels for which at least one pixel is nonzero, or if you want to count pixels for which all of the components are are nonzero.
I suggest that when you assign to B, you use
B=double(any(B, 3));
0 Comments
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!