Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- input_image=imread('man.jpg');
- % figure;imshow(input_image);
- input_image=imresize(input_image,[480 642]);
- img_orig = double(input_image);
- %figure,imshow(input_image);
- diference = (abs(img_orig(:,:,1)-background(:,:,1)) > threshold) | (abs(img_orig(:,:,2) - background(:,:,2)) > threshold) ...
- | (abs(img_orig(:,:,3) - background(:,:,3)) > threshold);
- %figure;
- %imshow(diference);
- diference = bwmorph(diference,'close'); %remove small holes
- diference = bwmorph(diference,'open'); %remove small object
- diference = bwmorph(diference,'erode',2);
- b2=1000;
- bin= bwareaopen(diference,b2); %removes from a binary image all connected components (objects) that have fewer than 1000 pixels
- %figure;
- %imshow(bin);
- bin2=logical(bin);%convert to logical
- bin3=regionprops(bin2,'Boundingbox'); %measure the props of the smallest rectangle containing the region
- bin4=struct2cell(bin3);
- bin5=cell2mat(bin4);%image matrix
- [s1 s2]=size(bin5);%s1=rows s2=cols
- disp(bin5);
- %imc=imcrop(input_image,[bin5(1,1) bin5(1,2) bin5(1,3) bin5(1,4)]);
- %imshow(imc);
- imb=imcrop(bin,[bin5(1,1) bin5(1,2) bin5(1,3) bin5(1,4)]);
- bin_2=logical(imb);
- bin_3=regionprops(bin_2,'Centroid');
- distance=bin5(1,4)-bin_3.Centroid(2)+bin5(1,2);
- figure,imshow(input_image),title('Body'),hold on;
- rectangle('Position',[bin5(1,1),bin5(1,2),bin5(1,3),bin5(1,4)],'EdgeColor','g','LineWidth',2);
- line(bin_3.Centroid(1)+bin5(1,1), bin_3.Centroid(2)+bin5(1,2), 'Marker', '*', 'MarkerEdgeColor', 'r') ;
Advertisement
Add Comment
Please, Sign In to add comment