3

Is there a way to extract a rectangle of my choice from an image, maybe using numpy arrays? Most implementations available seem to be for regular sliding window solutions, but those always include steps, or rectangles of the same aspect ratio, or something like that.

Is it possible to provide the beginning x and y coordinates and the width and height (or ending x and y coordinates), and extract exactly that rectangle? Can this be done using numpy arrays alone? Or is there another way to do this?

10
  • In what format are your images? Commented May 22, 2014 at 7:46
  • They were originally jpeg images and I've converted them into numpy arrays. Commented May 22, 2014 at 7:47
  • 1
    What exactly do you mean my extract, select 3 points manually? And what should your output look like? Commented May 22, 2014 at 7:47
  • By extract I mean for eg if I have a 360x240 image, and I want to extract a rectangle with starting point (10,10) and size (100,200), then the output should be a 100x200 sub-image which starts from x=10 and y=10. Not manually, I'll be providing the patch particulars in the code. Commented May 22, 2014 at 7:49
  • 3
    Do you mean something like rect = np.copy(image[10:110, 10:210]) Commented May 22, 2014 at 7:57

1 Answer 1

3

The best way to do this would be slicing i.e.

rect = np.copy(img[y1:y1+height,x1:x1+width])

where (x1, y1) is the upper left corner of your rectangle.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.