question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Refactor and improve image resizing

See original GitHub issue

Is your feature request related to a problem? Please describe. The function plantcv.resize could be improved in a few ways. It currently allows for resizing the x and y dimensions using scaling factors, but resizing to an exact size may be desirable also. We also use a single, fixed interpolation method that may not yield optimal results in all cases.

Describe the solution you’d like I propose a few modifications to plantcv.resize and a new function.

  1. Move plantcv.resize to the transform subpackage: plantcv.transform.resize. This is both because it is a transformation of the input image and it’s consistent with scikit-image.
  2. Refactor plantcv.transform.resize to resize images to an exact size.
  3. In plantcv.transform.resize, if the new size is smaller than the input size, use the OpenCV interpolation method cv2.INTER_AREA. If the new size is larger than the input size, use the interpolation method cv2.INTER_CUBIC. (These are the generally recommended options, but we could point a user to the OpenCV function if they want more control than what we provide).
  4. Make a new function called something like plantcv.transform.resize_factor that combines the new features proposed for plantcv.transform.resize but uses the current feature of scaling the sizes by factors rather than exact sizes.
  5. To avoid redundancy, it may be useful to have a helper function set the interpolation method.

Describe alternatives you’ve considered These functions could be wrapped into one like the OpenCV function, but I think it’s simpler to have two smaller functions rather than twice the inputs to one.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
dschneiderchcommented, Dec 7, 2020

@nfahlgren probably not necessary. i can’t think of any applications for shear or skew over warp. it can always be revisited.

1reaction
nfahlgrencommented, Oct 16, 2020

Hi @DannieSheng, it did come to my mind while I was reviewing your PR! I realized that the resize function you proposed there does not use interpolation though, it either crops or pads as you said. Maybe now that I think about it, these could potentially be one function?

def resize(img, size, interpolation=True):
    # img = numpy.ndarray
    # size = tuple
    # interpolation = bool

    img_area = img.shape[0] * img.shape[1]
    new_area = size[0] * size[1]

    if interpolation:
        if new_area >= img_area:
            resized = cv2.resize(img, dsize=size, interpolation=cv2.INTER_CUBIC)
        else:
            resized = cv2.resize(img, dsize=size, interpolation=cv2.INTER_AREA)
    else:
        if new_area >= img_area:
            # pad
        else:
            # crop
    return resized
Read more comments on GitHub >

github_iconTop Results From Across the Web

Refactor: Scaling Images - LearnHowToProgram.com
In this lesson we will walk through retrieving higher-quality files from the Yelp API, and resizing them appropriately using Picasso in order to...
Read more >
refactor (bbb-web): Improve large images resizing and ...
Resize the images larger than allowed based on the new configs. maxImageWidth; maxImageHeight. It also removes the previous config. maxImageSize ❌
Read more >
Free Image Resizer: Resize Photos Online | Adobe Express
Resize your photos easily with the Adobe Express free image resizer. Simply upload your pictures, change the photo size, and download your new...
Read more >
BIRME - Bulk Image Resizing Made Easy 2.0 (Online & Free)
BIRME is a flexible and easy to use bulk image resizer. It can resize multiple images to any specific dimension and crop images...
Read more >
Resizing TIFF images using run(scale...) does not work!
Hi, I would like to enhance the resolution (or size) of several ... Resizing TIFF images using run(scale. ... REFactor = 10; run("Scale....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found