0
$\begingroup$

I am doing a project for cancer recognition. My data set has hunderds of images but not of equal size. I wanna resize them to the size of the smallest image. But I am wondering do you think using the cv2.resize will effect the quality of images and so the result of my work? If yes what I should do. If no please let me know.

Width disturbuation

enter image description here

higth disturbuation

enter image description here

$\endgroup$
2
$\begingroup$

Of course, making them smaller will cause loss of information. Since before you had N x M data points for each image to describe the content of the image, but after resizing you will have n x m (Where n and N denote the number of rows in an image, m and M denotes the number of columns in an image. Also, n <= N and/or m <= M). That is, a small number of pixels will result in less information.

Open CV's resize() function squeezes the image instead of cropping, meaning it preserves aspect ratio, original content but it displays objects or parts in the image with fewer pixels. To achieve it, Open CV uses the interpolation technique. (read more here)

Two solutions you can try:

  • If your smallest image's size does not differ much from the size of the majority of your image, then resize them to the smallest. Because in that case, if you have a good model, your performance will not be affected severely.

  • If your smallest image's size differs much from the majority, or in general you have a group of small images and big images which sizes differ a lot, then choose a threshold of minimum size to which you will resize the images and drop the images that have a size less than your threshold.

In both cases, you will lose data or information, it is inevitable. The best practice is to test various possibilities to see which works well. Look at the distribution of the sizes of your images, make your decision accordingly.

If the size of the smallest image is big enough, and the smallest image and the biggest image do not differ a lot in size, I would just resize them. Because it would at least, gives a chance to the model to capture the feature in the image. However, in the second case (dropping the small images), you would not even give that chance to the model.

$\endgroup$
9
  • $\begingroup$ Thanks for your answer, but they differ alot I have : smallest-width=219, largest-width= 1427 and smallest-higth=193 , largest-higth=1920 $\endgroup$ – Nagh Nov 2 '20 at 18:39
  • 1
    $\begingroup$ I would suggest this as a starting point - firstly resize the images to the smallest's size then, build a model for that. Afterward, gradually, increase the size and drop the small ones. But consider that sizes like 1427x1920 are too big for modelling (It will be impractical and useless since you cannot expect your future inputs will also be that big). Of course, I don't know too much about your data, but 256x256, 512x512 are good for modelling. Again consider your future inputs, what about they might be small, you won't be able to classify them using your model since... $\endgroup$ – Shahriyar Mammadli Nov 2 '20 at 19:12
  • 1
    $\begingroup$ ...you configured the model to bigger sizes. So, your approach should be experimental. If there are not too many small particles or details in your images, resizing would not ruin your model. Check some similar models that have been built. Most of them are built smaller than or equal to the size of 256x256. $\endgroup$ – Shahriyar Mammadli Nov 2 '20 at 19:14
  • $\begingroup$ thanks, I added disturbution of widths and higths in my question. should i go with 512*512? $\endgroup$ – Nagh Nov 2 '20 at 19:54
  • 1
    $\begingroup$ In the width histogram, majority's value seems like around 210-220 (that first peak), in the height histgram, again the first peak seems like having 240-250. Just count them simply, what percent of it is smaller than lets say 256 or something. $\endgroup$ – Shahriyar Mammadli Nov 2 '20 at 20:25
0
$\begingroup$

To discuss quality of the image we have to have formal definition of what quality means. Just the word quality is the opposite of quantity and its a bit vague. But lets settle for our "standard" definition of beeing more vague and blury. Sure that will happen because you are effectively squeezing the pixels. But that has not to be a bad thing, since it can help you to generalise.

There is no right or wrong, build a small dataset and test your hypothesis.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.