Skip to content

Commit 134e24a

Browse files
committed
document difference bw float and Float
1 parent 3c1fecb commit 134e24a

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

docs/src/tutorials/arrays_colors.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,56 @@ These values are close to the channels of `c`, but have been rounded
222222
off---each channel is encoded with only 8 bits, so some approximation
223223
of the exact floating-point value is unavoidable.
224224

225+
## Preserving colorant type while conversion
226+
227+
While using `Float32`, `Float64` to convert the raw storage type of an image,
228+
the color space information is lost. Replacaing `Float32`, `Float64` with their lower-case
229+
forms preserves the colorant type.
230+
231+
- Grayscale Images
232+
233+
```jldoctest; setup = :(using ImageCore;)
234+
julia> c = Gray(0.5)
235+
Gray{Float64}(0.5)
236+
237+
julia> float64(c)
238+
Gray{Float64}(0.5)
239+
240+
julia> Float64(c)
241+
0.5
242+
```
243+
- Color Images
244+
245+
```jldoctest; setup = :(using ImageCore;)
246+
julia> c = RGB(0.2, 0.4, 0.8)
247+
RGB{Float64}(0.2,0.4,0.8)
248+
249+
julia> float64(c)
250+
RGB{Float64}(0.2,0.4,0.8)
251+
252+
julia> Float64(c)
253+
ERROR: MethodError: no method matching Float64(::RGB{Float64})
254+
Closest candidates are:
255+
Float32(::Int8) at float.jl:60
256+
Float32(::Int16) at float.jl:60
257+
Float32(::Int32) at float.jl:60
258+
...
259+
Stacktrace:
260+
[...]
261+
```
262+
**Note**: `Float64(rgb_c)` throws error because it does not implicitly convert RGB to single channel.
263+
264+
| Storage Type | Alternative |
265+
|--- |--- |
266+
| `Float32` | [`float32`](@ref) |
267+
| `Float64` | [`float64`](@ref) |
268+
| `N0f8` | [`n0f8`](@ref) |
269+
| `N6f10` | [`n6f10`](@ref) |
270+
| `N4f12` | [`n4f12`](@ref) |
271+
| `N2f14` | [`n2f14`](@ref) |
272+
| `N0f16` | [`n0f16`](@ref) |
273+
274+
225275
## [A consistent scale for floating-point and "integer" colors: fixed-point numbers](@id fixedpoint)
226276

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

0 commit comments

Comments
 (0)