Giter Site home page Giter Site logo

resizer's Introduction

Resizer

The only way to resize images


This image-resize funuction is used for image enhancement and restoration challenges, especially super-resolution.
It is made to address some crucial issues that are not solved by other resizing packages.
The code is mostly based on MATLAB's imresize function, but with a few crucial extra features. It is specifically useful due to the following reasons:

  1. None of the Python packages I am aware of, currently resizes images with results similar to MATLAB's imresize (which is a common benchmark for image resotration tasks, especially super-resolution).

  2. You can be accurate and consistent by specifying both scale-factor and output-size. This is an important feature for super-resolution and learning because one must acknowledge that the same outpu-size can be resulted with varying scale-factors. best explained by example: say you have an image of size 9x9 and you resize by scale-factor of 0.5. Result size is 5x5. now you resize with scale-factor of 2. you get result sized 10x10. "no big deal" ,you must thinking now, "I can resize it to output-size 9x9", right? but then you will not get the correct scale-fcator which is calculated as output-size / input-size = 1.8.
    This is one of the main reasons for creating this as this consistency is often crucial for learning based tasks.

  3. In addition to the common resizing methods (linear, cubic, lanczos etc.), you can specify a numeric array as a resizing kernel and use it to resize the image.

  4. You can resize N-D images.

  5. Some existing packages return misaligned results. it is visually not apparent but can cause great damage to image enhancement tasks.(https://hackernoon.com/how-tensorflows-tf-image-resize-stole-60-days-of-my-life-aba5eb093f35)

  6. You can specify a list of scale-factors to resize each dimension using a different scale-factor.


Cite / credit

If you find our work useful in your research or publication, please cite this work:

@misc{Resizer,
  author = {Assaf Shocher},
  title = {Resizer: Only way to resize},
  year = {2018},
  publisher = {GitHub},
  journal = {GitHub repository},
  howpublished = {\url{https://github.com/assafshocher/resizer}},
}

Usage:

resizer.imresize(im, scale_factor=None, output_shape=None, kernel=None, antialiasing=True, kernel_shift_flag=False)

im :
the input image

scale_factor:
can be specified as-

  1. one scalar scale - then it will be assumed that you want to resize first two dims with this scale.
  2. a list or array of scales - one for each dimension you want to resize. note: if length of the list is L then first L dims will be rescaled.
  3. not specified - then it will be calculated using output_size. this is not recomended (see advantage 2 in the list above).

output_shape:
A list or array with same length as im.shape. if not specified, can be calcualated from scale_factor

kernel:
Can be one of the following strings: "cubic", "lanczos2", "lanczos3", "box", "linear" (or other methods you may add). Or a 2D numpy array if the numeric kernel option is wanted.

antialiasing:
This is an option similar to MATLAB's default. only relevant for downscaling. if true it basicly means that the kernel is stretched with 1/scale_factor to prevent aliasing (low-pass filtering)

kernel_shift_flag:
this is an option made to automatically fix misalignment of kernel center of mass, by shifting it so that the resized result is aligned exactly (resizing with any regular method will align it perfectly to input image) (see comment inside the function for further info). the drawback here is that shifting the kenrel uses interpolation which can potentially harm accuracy. however it is sometimes crucial and furthermore this damage is neglegable in any application I tested.

resizer's People

Contributors

assafshocher avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.