0

I have multiple images and I am using imcrop function to take ROI in image. The problem with imcrop is it gives me different size of ROI on each image. I would like to take ROI of same size for each image. There is a option in imcrop by which I can select size but for that I need to keep my location of ROI fix. I want to fix window size but vary location of window on image. Is there a function available for this functionality in Matlab?

Mike 'Pomax' Kamermans
  • 49,297
  • 16
  • 112
  • 153
user2179080
  • 11
  • 2
  • 3
  • "same size" in pixels, or in % of image? What is wrong with `myROI = myImage(offsetY + (1:sizeY), offsetX + (1:sizeX));`? – Floris Mar 19 '13 at 16:11
  • I would like to use size in pixels. In Imcrop I get a rectangle and I use that rectangle to select ROI on image. But you can resize rectangle in Imcrop. I want rectangle size fix and I should be able to move rectangle on image and select desired ROI. – user2179080 Mar 19 '13 at 16:18

2 Answers2

1

I believe I have found the solution for cropping fixed sized window from image (interactively).

img = imread('circuit.tif'); %your image
imshow(img);

h = imrect(gca, [75 68 130 112]);
setResizable(h,0)
position = wait(h);
imgc = imcrop(img,position);
figure();
imshow(imgc);

Using imrect allows you to set your standard [xmin ymin width height] parameters. Set xmin and ymin to anything (0,0; approximate position) and width and hight to desired values.

Now you can drag your cropping window around the image and double click it when done.

regards, Piter71

Piter71
  • 11
  • 1
0

Firstly, I do not see a problem with imcrop. It takes a rectangle [xmin ymin width height] as input. So if you want to keep the size fixed, you have to keep width and height fixed and change xmin and ymin which is the top-left corner of the rectangle.

I would like to tell you one more function which can be used i.e. roipoly. You give the coordinates of vertices as the input to the function along with image. So if you want a hexagonal ROI, you would give 6 points as input. You then get a binary mask which you can multiply to get your ROI.

Autonomous
  • 8,935
  • 1
  • 38
  • 77