@@ -222,6 +222,57 @@ These values are close to the channels of `c`, but have been rounded
222222off---each channel is encoded with only 8 bits, so some approximation
223223of 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 TestImages, ImageCore; img = testimage("cameraman");)
234+ julia> summary(img)
235+ "512×512 Array{Gray{N0f8},2} with eltype Gray{Normed{UInt8,8}}"
236+
237+ julia> summary(float32.(img))
238+ "512×512 Array{Gray{Float32},2} with eltype Gray{Float32}"
239+
240+ julia> summary(Float32.(img))
241+ "512×512 Array{Float32,2}"
242+ ```
243+ - Color Images
244+
245+ ``` jldoctest; setup = :(using TestImages, ImageCore; img = testimage("fabio_color_256");)
246+ julia> summary(img)
247+ "256×256 Array{RGB{N0f8},2} with eltype RGB{Normed{UInt8,8}}"
248+
249+ julia> summary(float32.(img))
250+ "256×256 Array{RGB{Float32},2} with eltype RGB{Float32}"
251+
252+ julia> summary(Float32.(img))
253+ ERROR: MethodError: no method matching Float32(::RGB{Normed{UInt8,8}})
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_img) ` throws error because it does not implicitly
263+ convert RGB to single channel but ` float64.(rgb_img) ` works as expected.
264+
265+ | Storage Type | Alternative |
266+ | --- | --- |
267+ | ` Float32 ` | [ ` float32 ` ] ( @ref ) |
268+ | ` Float64 ` | [ ` float64 ` ] ( @ref ) |
269+ | ` N0f8 ` | [ ` n0f8 ` ] ( @ref ) |
270+ | ` N6f10 ` | [ ` n6f10 ` ] ( @ref ) |
271+ | ` N4f12 ` | [ ` n4f12 ` ] ( @ref ) |
272+ | ` N2f14 ` | [ ` n2f14 ` ] ( @ref ) |
273+ | ` N0f16 ` | [ ` n0f16 ` ] ( @ref ) |
274+
275+
225276## [ A consistent scale for floating-point and "integer" colors: fixed-point numbers] (@id fixedpoint)
226277
227278` c24 ` does not have an ` r ` field, but we can still use ` red ` to
0 commit comments