You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am having trouble saving 1 bit images. Do you know of a method that should work?
I am using →
[731e570b] TiffImages v0.11.0 in Julia
julia> versioninfo()
Julia Version 1.10.0
Commit 3120989f39 (2023-12-25 18:01 UTC)
Build Info:
Official https://julialang.org/ release
Platform Info:
OS: Windows (x86_64-w64-mingw32)
CPU: 24 × 12th Gen Intel(R) Core(TM) i9-12950HX
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-15.0.7 (ORCJIT, alderlake)
Threads: 1 on 24 virtual cores
Environment:
JULIA_EDITOR = code
JULIA_NUM_THREADS =
using Pkg
Pkg.activate(".")
##
using TiffImages
## Make a grid pattern to of true values
image_data = fill(false, (100,100))
image_data[5:10:end,:] .= true
image_data[:,10:10:end] .= true
## Convert to color space data
image_gray_bool = Gray{Bool}.(image_data)
## Add tags to edit
image_tiff = TiffImages.DenseTaggedImage(image_gray_bool)
ifd = ifds(bit2Tiff)
# Tag 258 is BitsPerSample
ifd[UInt16(258)] = 0x0001
# Tag 262 is PhotmetricInterpretation
ifd[UInt16(262)] = 0x0000
# Tag 277 is SamplesPerPixel
ifd[UInt16(277)] = 0x0001
## Save the image from the Gray{Bool},2 data
save_path = pwd() * "\\gray_bool.tif"
TiffImages.save(save_path, image_tiff)
##
inspection_image = TiffImages.load(save_path)
println(typeof(inspection_image))
The result is "TiffImages.DenseTaggedImage{Gray{N0f8}, 2, UInt32, Matrix{Gray{N0f8}}}", an 8 bit image.
I have also tried the FixedPointNumbers approach.
using Pkg
Pkg.activate(".")
##
using TiffImages
## Make a grid pattern to of true values
image_data = fill(false, (100,100))
image_data[5:10:end,:] .= true
image_data[:,10:10:end] .= true
## Convert to color space data
image_gray_N7f1 = Gray{N7f1}.(image_data)
## Add tags to edit
image_tiff = TiffImages.DenseTaggedImage(image_gray_N7f1)
ifd = ifds(bit2Tiff)
# Tag 258 is BitsPerSample
ifd[UInt16(258)] = 0x0001
# Tag 262 is PhotmetricInterpretation
ifd[UInt16(262)] = 0x0000
# Tag 277 is SamplesPerPixel
ifd[UInt16(277)] = 0x0001
## Save the image from the Gray{Bool},2 data
save_path = pwd() * "\\gray_N7f1.tif"
TiffImages.save(save_path, image_tiff)
##
inspection_image = TiffImages.load(save_path)
println(typeof(inspection_image))
The result is TiffImages.DenseTaggedImage{Gray{N7f1}, 2, UInt32, Matrix{Gray{N7f1}}}, a 1 bit image. However, the data is distorted with seven 0's encoded before each 1 in the output. The image previews correctly in the Plots window in VSCode before saving.
Before from plots →
After save →
BitMatrix arrays have no supporting method and break the colors paradigm.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I am having trouble saving 1 bit images. Do you know of a method that should work?
I am using →
The result is "TiffImages.DenseTaggedImage{Gray{N0f8}, 2, UInt32, Matrix{Gray{N0f8}}}", an 8 bit image.
I have also tried the FixedPointNumbers approach.
The result is TiffImages.DenseTaggedImage{Gray{N7f1}, 2, UInt32, Matrix{Gray{N7f1}}}, a 1 bit image. However, the data is distorted with seven 0's encoded before each 1 in the output. The image previews correctly in the Plots window in VSCode before saving.
Before from plots →
After save →
BitMatrix arrays have no supporting method and break the colors paradigm.
Beta Was this translation helpful? Give feedback.
All reactions