Ask Your Question
0

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

asked 2020-05-16 15:47:32 -0600

Cătălina Sîrbu gravatar image

updated 2020-05-17 10:07:36 -0600

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

edit retag flag offensive close merge delete

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 ( 2020-05-18 01:55:14 -0600 )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.

Cătălina Sîrbu gravatar imageCătălina Sîrbu ( 2020-05-18 07:00:11 -0600 )edit

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 ( 2020-05-18 07:20:50 -0600 )edit

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

Cătălina Sîrbu gravatar imageCătălina Sîrbu ( 2020-05-18 13:48:52 -0600 )edit

1 answer

Sort by » oldest newest most voted
0

answered 2020-05-17 02:10:15 -0600

berak gravatar image

updated 2020-05-17 05:54:50 -0600

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] )

edit flag offensive delete link more

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?

Cătălina Sîrbu gravatar imageCătălina Sîrbu ( 2020-05-17 04:39:08 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2020-05-16 15:47:32 -0600

Seen: 2,513 times

Last updated: May 17 '20