choosing region of interest of an image (cropping problem)

4 次查看(过去 30 天)
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!!

回答(2 个)

Junaid
Junaid 2011-12-2
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 个评论
Shriram Nerkar
Shriram Nerkar 2015-2-27
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
Image Analyst 2011-12-2
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.

类别

Help CenterFile Exchange 中查找有关 Deep Learning for Image Processing 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by