{"id":16656322,"url":"https://github.com/alisinabh/nx_color","last_synced_at":"2025-04-09T18:20:51.012Z","repository":{"id":44423344,"uuid":"512056714","full_name":"alisinabh/nx_color","owner":"alisinabh","description":"Toolkit for managing colorspaces in Elixir Nx to use in Machine Learning.","archived":false,"fork":false,"pushed_at":"2022-07-18T12:32:40.000Z","size":58,"stargazers_count":7,"open_issues_count":5,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-04T12:56:20.792Z","etag":null,"topics":["colors","colorspaces","machine-learning","nx","tensor"],"latest_commit_sha":null,"homepage":"https://hexdocs.pm/nx_color/","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alisinabh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-07-09T00:21:34.000Z","updated_at":"2022-08-02T17:33:32.000Z","dependencies_parsed_at":"2022-09-26T21:21:10.901Z","dependency_job_id":null,"html_url":"https://github.com/alisinabh/nx_color","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alisinabh%2Fnx_color","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alisinabh%2Fnx_color/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alisinabh%2Fnx_color/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alisinabh%2Fnx_color/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alisinabh","download_url":"https://codeload.github.com/alisinabh/nx_color/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248085388,"owners_count":21045152,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["colors","colorspaces","machine-learning","nx","tensor"],"created_at":"2024-10-12T09:57:02.354Z","updated_at":"2025-04-09T18:20:50.972Z","avatar_url":"https://github.com/alisinabh.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NxColor\n\n[![Package](https://img.shields.io/badge/-Package-important)](https://hex.pm/packages/nx_color) [![Documentation](https://img.shields.io/badge/-Documentation-blueviolet)](https://hexdocs.pm/nx_color)\n\nColorspace conversion in Elixir Nx.\n\nWith NxColor you can convert images (to be precise, pixels) between various colorspaces\nlike RGB, CMYK or CIE-Lab.\n\nSince this is implemented using Elixir Nx, It should be really fast.\n\n## Installation\n\nNxColor can be installed by adding `nx_color` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:nx_color, \"~\u003e 0.0.1-dev\"}\n  ]\nend\n```\n\n## Usage\n\nUsing libraries like [stb_image](https://hex.pm/packages/stb_image) or using an already loaded\nimage or images in an Nx.Tensor, You can import them into NxColor using the `NxColor.from_nx`\nfunction.\n\n```elixir\nstb_image = StbImage.read_file!(\"image.jpg\")\n\nimage =\n  stb_image\n  |\u003e StbImage.to_nx()\n  |\u003e NxColor.from_nx(colorspace: NxColor.Colorspace.RGB, channel: :last)\n```\n\nThen you can use `NxColor.change_colorspace` to actually convert the colorspace of the image.\n\nYou can see the list of all available colorspaces in the [documentation](https://hexdocs.pm/nx_color/NxColor.html).\n\n```elixir\nimage = NxColor.change_colorspace(image, NxColor.Colorspace.CMYK)\n```\n\nAfter you are done with the conversions, You can convert your image back to an Nx tensor.\n\n```elixir\ntensor = NxColor.to_nx(image, channel: :last)\n```\n\n### The channel option\n\nUsually there are two ways of representing images in tensors.\n\nLet's say we have a 32 x 32 image in the RGB colorspace. Each pixel in that colorspace\nis represented by 3 different number. **R**ed **G**reen and **B**lue.\n\nThe first way is if we encode the colors (the channel) as the **first** dimension in each image.\nSo the shape for our image tensor would be: `{3, 32, 32}`\n\nThe second way is if we encode the colors (the channel) as the **last** dimension in each image.\nSo the shape of our image tensor in this case would be: `{32, 32, 3}`\n\nIn NxColor you can choose between these two based on you input data and also your use-case.\nSimply set the `channel` option in `NxColor.from_nx` and `NxColor.to_nx` either to `:first` or `:last`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falisinabh%2Fnx_color","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falisinabh%2Fnx_color","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falisinabh%2Fnx_color/lists"}