Skip to content

Commit

Permalink
document difference bw float and Float
Browse files Browse the repository at this point in the history
  • Loading branch information
mgautam98 committed Jul 2, 2020
1 parent 3c1fecb commit d513c22
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions docs/src/tutorials/arrays_colors.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,57 @@ These values are close to the channels of `c`, but have been rounded
off---each channel is encoded with only 8 bits, so some approximation
of the exact floating-point value is unavoidable.

## Preserving colorant type while conversion

While using `Float32`, `Float64` to convert the raw storage type of an image,
the color space information is lost. Replacaing Float32, Float64 with their lower-case
forms preserves the colorant type.

- Grayscale Images

```jldoctest; setup = :(using TestImages, ImageCore; img = testimage("cameraman");)
julia> summary(img)
"512×512 Array{Gray{N0f8},2} with eltype Gray{Normed{UInt8,8}}"
julia> summary(float32.(img))
"512×512 Array{Gray{Float32},2} with eltype Gray{Float32}"
julia> summary(Float32.(img))
"512×512 Array{Float32,2}"
```
- Color Images

```jldoctest; setup = :(using TestImages, ImageCore; img = testimage("fabio_color_256");)
julia> summary(img)
"256×256 Array{RGB{N0f8},2} with eltype RGB{Normed{UInt8,8}}"
julia> summary(float32.(img))
"256×256 Array{RGB{Float32},2} with eltype RGB{Float32}"
julia> summary(Float32.(img))
ERROR: MethodError: no method matching Float32(::RGB{Normed{UInt8,8}})
Closest candidates are:
Float32(::Int8) at float.jl:60
Float32(::Int16) at float.jl:60
Float32(::Int32) at float.jl:60
...
Stacktrace:
[...]
```
**Note**: `Float64.(rgb_img)` throws error because it does not implicitly
convert RGB to single channel but `float64.(rgb_img)` works as expected.

| Storage Type | Alternative |
|--- |--- |
| `Float32` | [`float32`](@ref) |
| `Float64` | [`float64`](@ref) |
| `N0f8` | [`n0f8`](@ref) |
| `N6f10` | [`n6f10`](@ref) |
| `N4f12` | [`n4f12`](@ref) |
| `N2f14` | [`n2f14`](@ref) |
| `N0f16` | [`n0f16`](@ref) |


## [A consistent scale for floating-point and "integer" colors: fixed-point numbers](@id fixedpoint)

`c24` does not have an `r` field, but we can still use `red` to
Expand Down

0 comments on commit d513c22

Please sign in to comment.