Guest User

code-body detection

a guest
May 3rd, 2012
555
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1.  
  2.  
  3.  
  4. input_image=imread('man.jpg');
  5. % figure;imshow(input_image);
  6. input_image=imresize(input_image,[480 642]);
  7. img_orig = double(input_image);
  8.  
  9. %figure,imshow(input_image);
  10.  
  11.  
  12. diference = (abs(img_orig(:,:,1)-background(:,:,1)) > threshold) | (abs(img_orig(:,:,2) - background(:,:,2)) > threshold) ...
  13. | (abs(img_orig(:,:,3) - background(:,:,3)) > threshold);
  14.  
  15. %figure;
  16. %imshow(diference);
  17. diference = bwmorph(diference,'close'); %remove small holes
  18. diference = bwmorph(diference,'open'); %remove small object
  19. diference = bwmorph(diference,'erode',2);
  20. b2=1000;
  21. bin= bwareaopen(diference,b2); %removes from a binary image all connected components (objects) that have fewer than 1000 pixels
  22. %figure;
  23. %imshow(bin);
  24.  
  25. bin2=logical(bin);%convert to logical
  26. bin3=regionprops(bin2,'Boundingbox'); %measure the props of the smallest rectangle containing the region
  27. bin4=struct2cell(bin3);
  28. bin5=cell2mat(bin4);%image matrix
  29. [s1 s2]=size(bin5);%s1=rows s2=cols
  30. disp(bin5);
  31. %imc=imcrop(input_image,[bin5(1,1) bin5(1,2) bin5(1,3) bin5(1,4)]);
  32. %imshow(imc);
  33. imb=imcrop(bin,[bin5(1,1) bin5(1,2) bin5(1,3) bin5(1,4)]);
  34. bin_2=logical(imb);
  35. bin_3=regionprops(bin_2,'Centroid');
  36. distance=bin5(1,4)-bin_3.Centroid(2)+bin5(1,2);
  37. figure,imshow(input_image),title('Body'),hold on;
  38. rectangle('Position',[bin5(1,1),bin5(1,2),bin5(1,3),bin5(1,4)],'EdgeColor','g','LineWidth',2);
  39. 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