how to store the image into another matrix?
1 次查看(过去 30 天)
显示 更早的评论
I am trying to extract the object from the image i am using the code as
i = imread('2.jpg');
p = rgb2gray(i);
figure, imshow(p);
[r, n] = size(p);
%q = r/2;
l = n/2;
for j=1:r
for k=1:l
i1(j,k)=p(j,k);
end
end
for j1=1:r
for k1=l:n
i2(j1,k1)=p(j1,k1);
end
end
n1 = p(:,1 : end/2);
n2 = p(:,end/2+1 : end);
%figure,imshow(n1);
%figure, imshow(n2);
diff = imhist(n2)-imhist(n1);
thre = 100 * graythresh(diff);
disp(thre);
c = zeros(size(p));
%a = size(p);
[r2, n3]=size(p);
for j2=1:r2
for k2=1:n3
if p(j2,k2) < thre
c(j2,k2)=p(j2,k2);
else
c(j2,k2)=0;
end
end
end
disp(c);
figure, imshow(c);
i2 = edge(c,'sobel',0);
figure,imshow(i2);
se = strel('square',2);
i22 = imclose(i2,se);
% figure,imshow(i2);title('canny');
figure,imshow(i22);title('close line');
se = strel('square',2);
%se0 = strel('line',4,0);
i3 = imdilate(i22,se);
i4 = imfill(i3,'holes');
%[Ilabel num] = bwlabel(i4);
BW2 = bwareaopen(i4, 1000);
%d=bwmorph(BW2,'remove');
d=medfilt2(BW2,[3 3]); %median filter
%e=imclearborder(d);
[L,NUM]=bwlabel(d);
disp(L);
figure, imshow(p);title('gray');
figure, imshow(i2);title('sobel');
% figure, imshow(i3);title('dilate');
% figure, imshow(i4);title('fill holes');
figure, imshow(BW2);title('connected');
figure, imshow(d);title('median filter');
%figure, imshow(e);title('clear border');
%figure, imshow(i11);title('adjust');
m=1;
for i=1:NUM
figure,imshow(L==i),title('object i');
% [r1, n1] = size(L==i);
% for k=1:r1
% for l=1:n1
% jm(k,l) = L(k,l);
% end
% end
% m=m+1;
pause(1);
end
%figure, imshow(j1);
disp(NUM);
I am successful upto displaying the objects individually. But the problem is i am unable to store the image with objects individually into another matrix for my use
please any one help me to store the each object individually into new matrix.
thanks in advance who help me.
0 个评论
回答(1 个)
Image Analyst
2013-8-31
See my Image segmentation tutorial: http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862 where I do exactly that. Each object goes into it's own image using the bounding box (because, of course, images must be rectangular arrays).
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!