choosing region of interest of an image (cropping problem)
2 views (last 30 days)
Show older comments
i have project working on palmprint recognition, my question is i need to get a region of interest first on the image with 128x128 size, the shown code can crop an image manually, but i prefer it to be cropping with fixed size 128x128. This is the code i'm working on:
img = imread('image.jpg');
img = rgb2gray(img);
h_im = imshow(img);
e = imrect(gca,[320 240 128 128]);
BW = imcrop(img,e);
imshow(BW)
maybe you guys can help me??
thank you very much!!
0 Comments
Answers (2)
Junaid
on 2 Dec 2011
Dear you just have to drag the mouse to make rectangle and then right click and select "Copy position". The cropped region will be save in BW in your code. or If you know which area to crop then you can simple do it with taking any input for rectangle. then your code should be like this
img = imread('image.jpg');
img = rgb2gray(img);
h_im = imshow(img);
%e = imrect(gca,[320 240 128 128]);
e = [320 240 128 128];
BW = imcrop(img,e);
imshow(BW)
For more information to play with crop tool, visit the link below.
4 Comments
Shriram Nerkar
on 27 Feb 2015
The demo code involves for single image and one need to draw it by freehand method but what about if multiple images will having same ROI like circle. can you please show how to automate this.
Image Analyst
on 2 Dec 2011
To do like Photoshop does, where you move the mouse (array) and a box of fixed size follows it around, you'd have to put in code for the mousemove event and use rectangle() to draw a box of that fixed size at every current x,y location. Basically every time you move the mouse, your mousemove callback gets called and in that callback you get the current x,y location and use rectangle to draw a box there. When they "click" you "drop" the box there and perhaps set some flag that says you're not in the "box-moving" mode anymore. In the callback you'd just immediately exit if the flag is not correct, so that you're not moving every time the mouse goes over the image, just when you're in a "box moving" mode.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!