Image is flipped when using ```image_read()```
Hello.
When loading an image using image_read() to then display it, the image is automatically flipped. I need the image to be loaded exactly as it is originally.
Image is vertical
But loaded horizontally
The code:
library(magick)
im <- image_read(path_to_im)
image_ggplot(im)
I cannot reproduce this, for the image that I have it works fine.
Can you share your sessionInfo() and magick_config() ?
Btw you can also display it simply with print(im) or plot(im).
Hi @jeroen , below, I share both sessionInfo() and magick_config():
> my.session <- sessionInfo()
> print(my.session)
R version 4.3.3 (2024-02-29 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 11 x64 (build 22631)
Matrix products: default
locale:
[1] LC_COLLATE=Spanish_Spain.utf8 LC_CTYPE=Spanish_Spain.utf8
[3] LC_MONETARY=Spanish_Spain.utf8 LC_NUMERIC=C
[5] LC_TIME=Spanish_Spain.utf8
time zone: Europe/Madrid
tzcode source: internal
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] lubridate_1.9.3 forcats_1.0.0 stringr_1.5.1 dplyr_1.1.4
[5] purrr_1.0.2 readr_2.1.5 tidyr_1.3.1 tibble_3.2.1
[9] ggplot2_3.5.0 tidyverse_2.0.0 magick_2.8.3
loaded via a namespace (and not attached):
[1] tidyselect_1.2.1 blob_1.2.4
[3] tensorflow_2.16.0.9000 fastmap_1.1.1
[5] combinat_0.0-8 promises_1.2.1
[7] XML_3.99-0.16.1 digest_0.6.35
[9] timechange_0.3.0 lifecycle_1.0.4
[11] sf_1.0-16 processx_3.8.4
[13] magrittr_2.0.3 compiler_4.3.3
[15] rlang_1.1.3 tools_4.3.3
[17] utf8_1.2.4 yaml_2.3.8
[19] knitr_1.45 labeling_0.4.3
[21] htmlwidgets_1.6.4 bit_4.0.5
[23] sp_2.1-3 classInt_0.4-10
[25] reticulate_1.37.0 xml2_1.3.6
[27] abind_1.4-5 KernSmooth_2.23-22
[29] websocket_1.4.1 RImagePalette_0.1.1
[31] withr_3.0.0 grid_4.3.3
[33] fansi_1.0.6 colorspace_2.1-0
[35] e1071_1.7-14 scales_1.3.0
[37] zeallot_0.1.0 cli_3.6.2
[39] rmarkdown_2.26 generics_0.1.3
[41] stringdist_0.9.12 rstudioapi_0.16.0
[43] formattable_0.2.1 tzdb_0.4.0
[45] httr_1.4.7 image.ContourDetector_0.1.1
[47] sessioninfo_1.2.2 tfruns_1.5.3
[49] DBI_1.2.2 chromote_0.2.0
[51] proxy_0.4-27 rvest_1.0.4
[53] parallel_4.3.3 colordistance_1.1.2
[55] base64enc_0.1-3 keras3_1.1.0
[57] vctrs_0.6.5 Matrix_1.6-5
[59] jsonlite_1.8.8 hms_1.1.3
[61] bit64_4.0.5 imgpalr_0.3.2
[63] units_0.8-5 glue_1.7.0
[65] ps_1.7.6 stringi_1.8.3
[67] gtable_0.3.5 later_1.3.2
[69] quarto_1.4 munsell_0.5.1
[71] pillar_1.9.0 RPostgres_1.4.6
[73] RoughSets_1.3-8 htmltools_0.5.8
[75] R6_2.5.1 evaluate_0.23
[77] lattice_0.22-5 png_0.1-8
[79] openxlsx_4.2.5.2 class_7.3-22
[81] Rcpp_1.0.12 zip_2.3.1
[83] whisker_0.4.1 xfun_0.43
[85] tfdatasets_2.17.0 pkgconfig_2.0.3
> magick_config()
$version
[1] ‘6.9.12.98’
$modules
[1] FALSE
$cairo
[1] TRUE
$fontconfig
[1] FALSE
$freetype
[1] TRUE
$fftw
[1] TRUE
$ghostscript
[1] TRUE
$heic
[1] TRUE
$jpeg
[1] TRUE
$lcms
[1] TRUE
$libopenjp2
[1] TRUE
$lzma
[1] TRUE
$pangocairo
[1] TRUE
$pango
[1] TRUE
$png
[1] TRUE
$raw
[1] TRUE
$rsvg
[1] TRUE
$tiff
[1] TRUE
$webp
[1] TRUE
$wmf
[1] FALSE
$x11
[1] FALSE
$xml
[1] TRUE
$`zero-configuration`
[1] TRUE
$threads
[1] 1
I must say that in a different context, I wouldn't open an issue about this, but my current task requires to treat images differently (in this case, paintings) depending on whether they are horizontal or vertical, therefore, the library loading them wrong gets the data wrong, for example, for the above image:
> target_size <- 255
> im <- image_read(paste0('sample/',im.path))
> image_info(image_scale(im,target_size))
# A tibble: 1 × 7
format width height colorspace matte filesize density
<chr> <int> <int> <chr> <lgl> <int> <chr>
1 JPEG 255 191 sRGB FALSE 0 300x300
Both width and height are incorrect. Some images are loaded correctly while others don't.
Does image_orient() help? Like:
im <- image_read(path_to_im) %>% image_orient()