GithubHelp home page GithubHelp logo

alisinabh / nx_color Goto Github PK

View Code? Open in Web Editor NEW
7.0 3.0 0.0 58 KB

Toolkit for managing colorspaces in Elixir Nx to use in Machine Learning.

Home Page: https://hexdocs.pm/nx_color/

License: Apache License 2.0

Elixir 100.00%
nx colors colorspaces machine-learning tensor

nx_color's Introduction

NxColor

Package Documentation

Colorspace conversion in Elixir Nx.

With NxColor you can convert images (to be precise, pixels) between various colorspaces like RGB, CMYK or CIE-Lab.

Since this is implemented using Elixir Nx, It should be really fast.

Installation

NxColor can be installed by adding nx_color to your list of dependencies in mix.exs:

def deps do
  [
    {:nx_color, "~> 0.0.1-dev"}
  ]
end

Usage

Using libraries like stb_image or using an already loaded image or images in an Nx.Tensor, You can import them into NxColor using the NxColor.from_nx function.

stb_image = StbImage.read_file!("image.jpg")

image =
  stb_image
  |> StbImage.to_nx()
  |> NxColor.from_nx(colorspace: NxColor.Colorspace.RGB, channel: :last)

Then you can use NxColor.change_colorspace to actually convert the colorspace of the image.

You can see the list of all available colorspaces in the documentation.

image = NxColor.change_colorspace(image, NxColor.Colorspace.CMYK)

After you are done with the conversions, You can convert your image back to an Nx tensor.

tensor = NxColor.to_nx(image, channel: :last)

The channel option

Usually there are two ways of representing images in tensors.

Let's say we have a 32 x 32 image in the RGB colorspace. Each pixel in that colorspace is represented by 3 different number. Red Green and Blue.

The first way is if we encode the colors (the channel) as the first dimension in each image. So the shape for our image tensor would be: {3, 32, 32}

The second way is if we encode the colors (the channel) as the last dimension in each image. So the shape of our image tensor in this case would be: {32, 32, 3}

In NxColor you can choose between these two based on you input data and also your use-case. Simply set the channel option in NxColor.from_nx and NxColor.to_nx either to :first or :last.

nx_color's People

Contributors

alisinabh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

nx_color's Issues

Add more testing cases using scikit image

We need more test cases. The best scenario is if we grab a few real images and convert their colorspaces using scikit image then save them as the results of our test cases.

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.