Code Monkey home page Code Monkey logo

pyimage's Introduction

#Image Procecessing in Python

If you are interested in image classification problems, e.g. classifying dog from cat, female from male, etc, pyimage is designed to make image transformations and vectorization easy.


  1. First you need to download images you are interested to classify. By convention, the directory structure is such that under the parent directory, there are sub-directories containing images of each of the classes you are interested in. Here is a small dataset [1] containing images of cats and dogs. The parent directory is cat_dog, and the sub-directories are cat and dog.


  2. Import the ImagePipeline class and instantiate by providing the path of the parent path:

    from pyimage.pipeline import ImagePipeline
    pipe = ImagePipeline('path/to/cat_dog')

  3. Read the images in by using the read function. The read function accepts an optional sub_dirs argument which is a tuple of the sub-directory names. If no argument is provided, all the sub-directories are read. The images are stored as a list of list (of matrices) in the instance variable img_lst2.

    pipe.read(sub_dirs=('cat', 'dog'))

  4. Resize the images by providing the dimensions. The images are by default read in as a 3D tensor, therefore the dimension argument must be a tuple of 3.

    pipe.resize((300, 300, 3))

  5. If you are interested to view some of your images anytime along your resizing/transformation steps, you can use the show function. The first argument is the name of sub-directory and the second argument is the nth image in the sub-directory you would want to view.

    pipe.show('cat', 0)

  6. To transform all the images, use the transform function. The first arugment is the transformation function, usually a function from skimage. The second argument is a dictionary of the additional arguments needed for the transformation function.

    from skimage.color import rgb2gray
    pipe.transform(rgb2gray, {})
    pipe.show('cat', 0)

    If you want to just transform one image instead of all the images to see what the effects are like, the third and four arguments are the name of the sub-directory and the nth image you want to apply the transformation to. The function will be applied to the one image, but not change the original copy.

    from skimage.feature import canny
    pipe.transform(canny, {}, 'cat', 0)

  7. When you have done all the necessary transformations, call vectorize. The images will be flattened to form a feature matrix where each row are the pixels of an image. The class labels are also generated as a vector. The feature matrix and label vector are accessible in the instance variable features and labels respectively.

    pipe.vectorize()
    pipe.features
    pipe.labels

References:

  1. Jeremy Elson, John R. Douceur, Jon Howell, Jared Saul, Asirra: A CAPTCHA that Exploits Interest-Aligned Manual Image Categorization, in Proceedings of 14th ACM Conference on Computer and Communications Security (CCS), Association for Computing Machinery, Inc., Oct. 2007

pyimage's People

Contributors

jyt109 avatar

Stargazers

 avatar

Watchers

 avatar  avatar  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.