-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from SomTambe/dev
Add basic functions for colorspace transforms.
- Loading branch information
Showing
15 changed files
with
380 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,9 @@ authors = ["SomTambe <[email protected]>"] | |
version = "0.1.0" | ||
|
||
[deps] | ||
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba" | ||
ChainRules = "082447d4-558c-5d27-93f4-14fc19e9eca2" | ||
Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c" | ||
ImageTransformations = "02fcd773-0e25-5acc-982a-7f6622650795" | ||
Images = "916415d5-f1e6-5110-898d-aaa5f9f070e0" | ||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" | ||
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[deps] | ||
Images = "916415d5-f1e6-5110-898d-aaa5f9f070e0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,33 @@ | ||
using Documenter, DiffImages | ||
|
||
makedocs(sitename="DiffImages.jl") | ||
makedocs(; | ||
modules = [DiffImages], | ||
doctest = true, | ||
authors = "Som V Tambe <[email protected]>", | ||
repo = "https://github.com/SomTambe/DiffImages.jl/blob/{commit}{path}#L{line}", | ||
sitename = "DiffImages.jl", | ||
# format = Documenter.HTML(; | ||
# prettyurls = get(ENV, "CI", "false") == "true", | ||
# canonical = "https://fluxml.ai/Flux3D.jl", | ||
# assets = String["assets/favicon.ico"], | ||
# analytics = "UA-154580699-2", | ||
# ), | ||
pages = [ | ||
"Home" => "index.md", | ||
# "Tutorials" => [ | ||
# ], | ||
"Colorspace Transforms" => "colors/index.md", | ||
# "Datasets" => | ||
# ["ModelNet" => "datasets/modelnet.md", "Custom Dataset" => "datasets/utils.md"], | ||
# "Transforms" => "api/transforms.md", | ||
# "Metrics" => "api/metrics.md", | ||
# "API Documentation" => [ | ||
# "Conversions" => "api/conversions.md", | ||
# "Helper function" => "api/utils.md", | ||
# "Visualization" => "api/visualize.md", | ||
# "3D Models" => "api/models.md", | ||
# ], | ||
], | ||
) | ||
|
||
deploydocs(; repo = "github.com/FluxML/Flux3D.jl.git") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
```@meta | ||
CurrentModule = DiffImages | ||
``` | ||
# Colorspace Transforms | ||
|
||
!!! note "Consistency with the batch dimension" | ||
Since we require the last dimension to be the batch dimension, | ||
kindly unsqueeze the last dimension if you would like to pass a | ||
single image. | ||
|
||
```@autodocs | ||
Modules = [DiffImages] | ||
Pages = ["colors/conversions.jl"] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
```@meta | ||
CurrentModule = DiffImages | ||
``` | ||
# DiffImages Documentation | ||
|
||
# DiffImages: Extending Automatic Differentiation support to the JuliaImages ecosystem | ||
|
||
```@autodocs | ||
Modules = [DiffImages] | ||
Pages = ["conversions.jl"] | ||
``` | ||
DiffImages.jl is a differentiable computer vision library made in pure Julia. It is being developed with the aim of extending AD support to the JuliaImages ecosystem. | ||
|
||
This library is under heavy development and is not intended for use yet. A stable release later will enable the users to readily use this. | ||
|
||
You can watch our development at the Discussions tab of our repository. We welcome all and everyone who intend to help us with their discussions. Open Source code simply cannot be made if the community does not give its inputs. | ||
|
||
We hope you remain safe and healthy. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
""" | ||
channelify(m::AbstractArray{CT,N}) where {CT <: Colorant, N} | ||
Channelify function. | ||
Input should be in ``WHN`` order ``\\implies (*, batch)``. | ||
Output will be in the order ``(*, channels, batch)``. | ||
# Examples | ||
```jldoctest; setup = :(using Images,DiffImages) | ||
julia> input_size = (16, 16, 2) | ||
(16, 16, 2) | ||
julia> size(channelify(HSV.(rand(BGR,input_size...)))) | ||
(16, 16, 3, 2) | ||
``` | ||
""" | ||
function channelify(m::AbstractArray{CT,N}) where {CT <: Colorant, N} | ||
e = eltype(m) | ||
m = channelview(m) | ||
if e <: AbstractGray | ||
m = reshape(m, 1, size(m)...) | ||
end | ||
t = ntuple(identity, ndims(m)) | ||
m = permutedims(m, (t[2:end-1]...,1,t[end])) | ||
return m | ||
end | ||
|
||
@adjoint function channelview(x::AbstractArray{T,N}) where {T, N} | ||
e = eltype(x) | ||
y = channelview(x) | ||
function pullback(Δ) | ||
return (collect(colorview(e,Δ)),) | ||
end | ||
return (y, pullback) | ||
end | ||
|
||
@adjoint function colorview(T, x) | ||
y = colorview(T,x) | ||
function pullback(Δ) | ||
return (nothing, channelview(Δ)) | ||
end | ||
return (y, pullback) | ||
end | ||
|
||
# adjoint for (::Colorant{T,N})(x::Real) | ||
for f in (:HSV,:AHSV,:HSVA, | ||
:Gray,:AGray,:GrayA, | ||
:HSL,:AHSL,:HSLA, | ||
:RGB,:ARGB,:RGBA, | ||
:BGR,:ABGR,:BGRA, | ||
:XYZ,:AXYZ,:XYZA, | ||
:xyY,:AxyY,:xyYA, | ||
:Lab,:ALab,:LabA, | ||
:Luv,:ALuv,:LuvA, | ||
:LCHab,:ALCHab,:LCHabA, | ||
:LCHuv,:ALCHuv,:LCHuvA, | ||
:DIN99,:ADIN99,:DIN99A, | ||
:LMS,:ALMS,:LMSA, | ||
:YIQ,:AYIQ,:YIQA) | ||
@eval @adjoint function $f(x::Real...) | ||
y = $f(x::Real...) | ||
function pull(Δ...) | ||
return (Δ...,) | ||
end | ||
return (y, pull) | ||
end | ||
end | ||
|
||
# Constructor adjoint | ||
# function ChainRules.rrule(::Type{HSL{T}}, x, y, z) where T <: AbstractFloat | ||
# β = HSL{T}(x, y, z) | ||
# function Lab_pullback(Δ) | ||
# @show Δ x y z β | ||
# return (ChainRules.NoTangent(),Δ.h,Δ.s,Δ.l) | ||
# end | ||
# return (β, Lab_pullback) | ||
# end | ||
|
||
""" | ||
colorify(color::Type{CT}, m::AbstractArray) where CT <: Colorant | ||
Colorify function. | ||
Expecting an input of the type ``(*, channels, batch)``. | ||
Converts the array to the `color` specified. | ||
# Examples | ||
```jldoctest; setup = :(using Images,DiffImages) | ||
julia> input_size = (25, 25, 3, 7) | ||
(25, 25, 3, 7) | ||
julia> size(colorify(HSV, rand(input_size...))) | ||
(25, 25, 7) | ||
``` | ||
""" | ||
function colorify(color::Type{CT}, m::AbstractArray) where CT <: Colorant | ||
t = ntuple(identity, ndims(m)) | ||
m = permutedims(m, (t[end-1],t[1:end-2]...,t[end])) | ||
if color <: AbstractGray | ||
m = dropdims(m; dims=1) | ||
end | ||
m = colorview(color, m) | ||
return m | ||
end | ||
# TODO: adjoints for `colorview(T, gray1, gray2...)` are not added yet. |
This file was deleted.
Oops, something went wrong.
Empty file.
Oops, something went wrong.