code is supposed to take the input image, extract the objects, then overlap circle masks of decreasing radius (r=64,.....1) on each object. A histogram of the no. of white pixels that coincide with the circle mask should be plotted. How do I proceed?
2 views (last 30 days)
Show older comments
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: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;
center = [64 64];
grayImage = rgb2gray(B)
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(grayImage).* circleMat;
ne(radius) = length(find(circle_image > 0))
end
figure,hist(ne);
xlabel('Overlapped white pixels');
ylabel('Frequency');
title('Histogram');
0 Comments
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!