Advertisement
Guest User

Untitled

a guest
Apr 6th, 2020
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.96 KB | None | 0 0
  1. function image = ques4(I)
  2.     bin = imbinarize(rgb2gray(I));
  3.     inv_bin = ~ bin;
  4.     [Lo, numo] = bwlabel(bin);
  5.     [Lh, numh] = bwlabel(inv_bin);
  6.    
  7.    
  8.     cnt = 0;
  9.     numh = numh -1;
  10.     stateo=regionprops (Lo, 'BoundingBox');
  11.     stateh=regionprops (Lh, 'BoundingBox')
  12.     s = 1;
  13.     for i = 1 : numo
  14.         Xo=uint64(stateo(i).BoundingBox(1));
  15.         Yo=uint64(stateo(i).BoundingBox(2));
  16.         Wo=stateo(i).BoundingBox(3);
  17.         Ho=stateo(i).BoundingBox(4);
  18.         if(bin(Yo, Xo) == 1)
  19.             for j = 1 : numh
  20.                 Xh=uint64(stateh(j).BoundingBox(1));
  21.                 Yh=uint64(stateh(j).BoundingBox(2));
  22.                 Wh=stateh(j).BoundingBox(3);
  23.                 Hh=stateh(j).BoundingBox(4);
  24.                 if (Xh>Xo && Yh>Yo && Xh<(Xo+Wo) && Yh<(Yo+Ho))
  25.                     image(s)=stateo(i);
  26.                     s = s + 1;
  27.                     break;
  28.                 end
  29.             end
  30.         end
  31.     end
  32. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement