JuliaImages / Images.jl

An image library for Julia
http://juliaimages.org/
Other
533 stars 141 forks source link

Applying rotation using Images.jl #640

Closed ereday closed 7 years ago

ereday commented 7 years ago

I couldn't find an example from which I could undestand usage of rotate. I tried the following but failed to rotate & save original image. Edit I prefer not to loose anyting from the image and for this I guess, I need to to add padding to this workflow too.


img = load("my_img.png") # 320×480 Array{RGBA{N0f8},2}:
tfm = recenter(RotMatrix(pi/8), center(img))
imgrot = warp(img, tfm)
save("rotated_my_img.png",imgrot)
timholy commented 7 years ago

Works for me. Using the "lighthouse" image from TestImages: rotated_my_img

As you can see, padding is added for you.

If you want more help, you'll have to be more explicit about what exactly is going wrong. Make sure you're using Images, CoordinateTransformations.

ereday commented 7 years ago

Thanks for the reply. I tried the same thing by using lighthouse image you mentioned:

using Images,TestImages,CoordinateTransformations
img = testimages("lighthouse") # 512×768 Array{RGB4{N0f8},2}
tfm = recenter(RotMatrix(pi/8), center(img)) 
imgrot = warp(img, tfm)

WARNING: 'warp(img, tform)' is deprecated in favour of the new interpretation 'warp(img, inv(tform))'. Set 'const warp = ImageTransformations.warp_new' right after package import to change to the new behaviour right away. See https://github.com/JuliaImages/ImageTransformations.jl/issues/25 for more background information in depwarn(::String, ::Symbol) at ./deprecated.jl:64 in warp_old(::Array{ColorTypes.RGB4{FixedPointNumbers.Normed{UInt8,8}},2}, ::CoordinateTransformations.AffineMap{Rotations.RotMatrix{2,Float64,4},StaticArrays.SVector{2,Float64}}) at /Users/ereday/.julia/v0.5/ImageTransformations/src/warp.jl:124 in eval(::Module, ::Any) at ./boot.jl:234 in eval(::Module, ::Any) at /usr/local/Cellar/julia/0.5.0/lib/julia/sys.dylib:? in eval_user_input(::Any, ::Base.REPL.REPLBackend) at ./REPL.jl:64 in macro expansion at ./REPL.jl:95 [inlined] in (::Base.REPL.##3#4{Base.REPL.REPLBackend})() at ./event.jl:68 while loading no file, in expression starting on line 0 -127:640×-68:837 OffsetArray{RGB4{N0f8},2}:

Now, If I try to save imgrot with: save("rotated_lhouse.jpg",imgrot)

I got first an error which states:

Errors encountered while saving "rotated_lhouse.jpg". All errors: MethodError(QuartzImageIO.to_explicit,(

and then millions of numbers starts to appear in the terminal and session is locked. `

My operating system is OSX and I'm using Julia v0.5.

timholy commented 7 years ago

This needs fixing in QuartzImageIO.jl (can you please report this there?) You can work around the bug with save("rotated_lhouse.jpg", parent(imgrot)). See this blog post for more information.