JuliaImages / JuliaImages/juliaimages.github.io

advertise `ccolor` in writing generic code

Open
#151 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

best practice
Dominant language
Julia
Stars
33
Forks
52
PR merge metrics
No merged PRs in 30d

Description

Functions in JuliaImages should accept both numerical array AbstractArray{<:Number} and colorant array Abstract{<:Colorant} if possible.

It is not uncommon to infer the return eltype in the beginning of the algorithm so as to pre-allocate array. I previously have two versions of codes to achieve this. The first version is:

function foo(img::AbstractArray{T}) where T<:Number
    CT = RGB{floattype(T)}
    ...
end

function foo(img::AbstractArray{T}) where T<:Colorant
    CT = RGB{floattype(eltype(T))}
    ...
end

Then one day I found out that eltype(Float32) == Float32, which make it possible to merge it into one method:

function foo(img::AbstractArray{T}) where T<:Number
    CT = RGB{floattype(eltype(T))}
    ...
end

As @kimikage pointed it out in https://github.com/JuliaGraphics/ColorTypes.jl/issues/201, ccolor does a similar thing more reliably (I assume so?):

function foo(img::AbstractArray{T}) where T<:Number
    CT = ccolor(RGB, floattype(T))
    ...
end

I feel this worth documenting somewhere in the tutorials; otherwise, it's like a missing spell and people repeatedly reinvent it.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the JuliaImages tutorials and reviewing where generic image-processing code is documented. Add a tutorial explanation of using ccolor with floattype for both numerical and colorant arrays, using the examples in this issue. Done means the pattern is documented clearly enough to prevent repeated reimplementation.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.