choosing region of interest of an image (cropping problem)
조회 수: 2 (최근 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!!
댓글 수: 0
답변 (2개)
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
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
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.
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!