GithubHelp home page GithubHelp logo

image-resizing's Introduction

Image-resizing

Image Resizing with Python

Tools and Languages:

OpenCV

VS Code

pip

Python


Installation

Use the package manager pip to install cv2 and numpy.

pip install cv2
pip install numpy

Import

import cv2
import numpy as np

Reading image from file

Here we are using 'cv2.imread()' method to read samples.

img = cv2.imread("cat.png")

Img resizing

Theory:(Demonstrated Down-scaling)

Here we are using a bit better method to resize an image, preserving the aspect-ratio rather than using normal resizing.
1.Set the scale-percentage i.e percentage upto which, we want to downscale.
2.Build new width of the resized image i.e (Original image width * scale_percent).
3.Build new height of the resized image i.e (Original image height * scale_percent).
4.Storing height and width.
In the next snippet we are using interpolation to finally resizing it.

scale_percent = 0.60
width = int(img.shape[1]*scale_percent)
height = int(img.shape[0]*scale_percent)
dim = (width,height)

Implementing interpolation

As we are demonstrating Down-scaling or shrinking the scale, we will be using cv2.INTER_AREA method of Interpolation

resized = cv2.resize(img,dim,interpolation = cv2.INTER_AREA)

Comparing original vs resized

cv2.imshow('ORIGINAL',img)
cv2.imshow('RESIZED',resized)
cv2.waitKey(0)
cv2.destroyAllWindows()

Images

Logo Resized

Developed by

Ashish ku. Behera

image-resizing's People

Contributors

ankush0939 avatar ashish-max avatar binayaksadangi avatar pygeekspro 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.