Ask Your Question
0

What is the difference between cropping an image and applying a ROI (region of interest) on the image

asked May 16 '0

Cătălina Sîrbu gravatar image

updated May 17 '0

EDIT:

Having a base image (640x640) I want to know if applying a rectangular white shape mask of (100x100), in another words, a ROI is more time consuming compared to cropping the image in the same rectangular shape (100x100).

What I consider as being a ROI

mask = np.zeros_like(original_image)
shape = np.array([[a,b,c,d]])
cv2.fillPoly(mask, shape, (255,255,255))
cv2.bitwise_and(original_image, mask)

The way of cropping

cropped = original_image[x:y, z:t]

I want to apply a function (e.g transform to grayscale) or apply a color filter on the image.

I think that doing so on the ROIed image will be more time consuming as there are many more pixels (the resulting image has the same dimensions as the original one (640x640)).

On the other hand, applying some function on the cropped image will take less time compared to the latter.

The question is: wouldn't the operation of cropping the image compensate the time needed to compute the rest of the 640x640 - 100x100 pixels?

Hope I was clear enough. Thanks in advance

Preview: (hide)

Comments

ah, alright, so it's cropping vs. masking, sorry, missed that.

but again, sorry to say so, its one of those cases, where you have to try on your own and measure.

berak gravatar imageberak (May 18 '0)edit
1

Hi, I did measure, and the result is obviously :

  • CROP TIMING: 11560.400000007576 us
  • ROI TIMING: 780580.8000000524 us

This was the result of using timeit library in python, with10000 iterations. The reason why I've asked this question is because I know the mask type operation takes more time related to crop, so I wanted to find if there is any way I can crop irregular shapes without using masks.

so I wanted to find if there is any way I can crop irregular shapes without using masks.

not directly. if your "irregular shape" only covers part of the image, you can still crop to the bounding box of that, and mask out the unwanted parts of it

berak gravatar imageberak (May 18 '0)edit

Could you please provide me more details? A link eventually?

1 answer

Sort by » oldest newest most voted
0

answered May 17 '0

berak gravatar image

updated May 17 '0

The question that arises immediately is: wouldn't the operation of cropping the image compensate the time needed to compute the rest of the 640x640 - 100x100 pixels ?

no, cropping is almost for free, an operation like:

cv:: Mat cropped = image(cv::Rect(10,10,100,100));

does not copy any memory, it returns a new Mat header with updated sizes, while the data points to the original memory (with some offset)

( same for numpy "slices" like image[10:110, 10:110] )

Preview: (hide)

Comments

Hi, thank you for the answer you provided. I have just modified my question to be more clear. I would like to ask youwhat is the difference between the ROI that i'm talking about vs the cropping method. When do you use each? If cropping is less time consuming (and also less processor consuming), why would I ever use the ROI method (the mask, the bitwise , etc) ? Tell me if I'm wrong: you can not crop an image in other shape than rectangular ones. For example if I would like to crop a shape of trapeze, I won't be able to do it, right?

Question Tools

1 follower

Stats

Asked: May 16 '0

Seen: 2,584 times

Last updated: May 17 '20