Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. function pixel_vals = boundingboxPixels(img, x_init, y_init, x_width, y_width)
  2.  
  3. if x_init > size(img,2)
  4. error('x_init lies outside the bounds of the image.'); end
  5. if y_init > size(img,1)
  6. error('y_init lies outside the bounds of the image.'); end
  7.  
  8. if y_init+y_width > size(img,1) || x_init+x_width > size(img,2) || ...
  9. x_init < 1 || y_init < 1
  10. warning([...
  11. 'Given rectangle partially falls outside image. ',...
  12. 'Resizing rectangle...']);
  13. end
  14.  
  15. x_min = max(1, uint16(x_init));
  16. y_min = max(1, uint16(y_init));
  17. x_max = min(size(img,2), x_min+uint16(x_width));
  18. y_max = min(size(img,1), y_min+uint16(y_width));
  19. x_range = x_min : x_max;
  20. y_range = y_min : y_max;
  21.  
  22. Upper = img( x_range, y_min , :);
  23. Left = img( x_min, y_range, :);
  24. Right = img( x_max, y_range, :);
  25. Lower = img( x_range, y_max , :);
  26.  
  27. pixel_vals = [...
  28. Upper
  29. permute(Left, [2 1 3])
  30. permute(Right, [2 1 3])
  31. Lower];
  32.  
  33. end
  34.  
  35. imgRect=getrect;//get a rectangle region in image
  36. cropedImg=imcrop(orgImg,[xtopleft ytopleft width height]);//in croppedImg you have the value of specified region
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement