JuliaIO / ImageMagick.jl

Thin Wrapper for the library ImageMagick
Other
53 stars 37 forks source link

[Help] Convert from Image File back to raw data #191

Closed jacksoncalvert closed 3 years ago

jacksoncalvert commented 3 years ago

Hi All, Just wondering if anybody knows how you could convert an image back into the {UInt8,1} form that data can come in as.

When Im loading an image, I load as

ImageMagik.load(IOBuffer(data)) 

to get it to an rbg format. Id like to get it back to the data format with a "reverse buffer" of some kind.

Cheers

IanButterworth commented 3 years ago

The most efficient would be to use channelview which you can check out here https://juliaimages.org/ImageCore.jl/v0.0.4/views.html

jacksoncalvert commented 3 years ago

The most efficient would be to use channelview which you can check out here https://juliaimages.org/ImageCore.jl/v0.0.4/views.html

Would I think just have to vec(rawview(channelview(image)))?

johnnychen94 commented 3 years ago

vec might be unnecessary here because we could do linear indexing in Julia: A[16] for size(A) == (4, 4)

An alternative to this is reinterpret:

julia> using ImageCore, ImageDistances, TestImages

julia> img = testimage("camera");

julia> img_raw = reinterpret(UInt8, img);

julia> euclidean(rawview(channelview(img)), img_raw)
0.0