How to Flip Images Vertically and Horizontally in Julia
Overview
This section introduces how to vertically or horizontally flip an image in Julia. It might seem intuitive to expect a function like flip
in Images.jl
, but it’s not present1. However, such functionality is implemented in the Augmentor.jl
package2. Considering dependencies, it’s inefficient to use a package just for the flipping feature, so let’s implement it using only built-in functions.
Code
We will use this example image.
Horizontal Flip rotr90(img')
Transpose the image and then rotate it 90 degrees with rotr90
.
Vertical Flip reverse(rotr90(img'))
Flip the horizontally flipped image using the reverse
function.
Complete Code
using Images
img = load("seola.png")
flipedH = rotr90(img')
flipedV = reverse(rotr90(img'))
save("seolaH.png", flipedH)
save("seolaV.png", flipedV)
See Also
Environment
- OS: Windows
- julia: v1.10.0