Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What is the default resize filter? #353

Open
cj-holmes opened this issue Jul 22, 2022 · 2 comments
Open

What is the default resize filter? #353

cj-holmes opened this issue Jul 22, 2022 · 2 comments

Comments

@cj-holmes
Copy link

Hi there, I have a question/help wanted issue.

I'm trying to work out what the default filter used with image_resize() is.
I see from the R package documentation that it is set to NULL image_resize(image, geometry = NULL, filter = NULL)

So I looked in the Magick++ documentation (https://www.imagemagick.org/Magick++/STL.html) and see that it might be Lanczos

Filter to use when resizing image. The reduction filter employed has a sigificant effect on the time required to resize an image and the resulting quality. The default filter is Lanczos which has been shown to produce good results when reducing images.

But when I compare an image resized with the default filter = NULL argument, and one resized by specifying filter = "Lanczos" - they are not the same (see example below). Is anyone able to help?

Thanks!

waldo::compare(
  image_read('https://www.r-project.org/logo/Rlogo.png') |> 
  image_resize("50x", filter = NULL) |>
  image_raster(),
  
  image_read('https://www.r-project.org/logo/Rlogo.png') |> 
  image_resize("50x", filter = "Lanczos") |>
  image_raster()
)

Output

old vs new
                      col
  old[9, ]    transparent
  old[10, ]   transparent
  old[11, ]   transparent
- old[12, ]   transparent
+ new[12, ]   #c0c2c502  
- old[13, ]   transparent
+ new[13, ]   #bfc2c504  
- old[14, ]   transparent
+ new[14, ]   #bebfc201  
  old[15, ]   transparent
  old[16, ]   transparent
- old[17, ]   #bec0c40b  
+ new[17, ]   transparent
- old[18, ]   #bec0c327  
+ new[18, ]   #bec1c416  
and 24 more ...
@cj-holmes
Copy link
Author

cj-holmes commented Jul 23, 2022

I have just discovered that using filter Undefined makes the outputs the same.
So what resize method is being used when filter = 'Undefined'?

waldo::compare(
  image_read('https://www.r-project.org/logo/Rlogo.png') |> 
    image_resize("50x", filter = NULL) |>
    image_raster(),
  
  image_read('https://www.r-project.org/logo/Rlogo.png') |> 
    image_resize("50x", filter = "Undefined") |>
    image_raster()
)

✔ No differences

@cj-holmes
Copy link
Author

OK, so I seem to be answering my own question here! But Ive just tested and it looks like the Undefined filter and the Mitchell filter return the same for me.

So is it the Mitchell filter that is used by default? Would love some help with this is possible!

o <-
  lapply(
  filter_types(),
  function(x){
    waldo::compare(
      magick::image_read('https://www.r-project.org/logo/Rlogo.png') |> 
        magick::image_resize("10x", filter = NULL) |>
        magick::image_raster(),
      
      magick::image_read('https://www.r-project.org/logo/Rlogo.png') |> 
        magick::image_resize("10x", filter = x) |>
        magick::image_raster()
    )
  })

filter_types()[which(lengths(o) == 0)]
[1] "Undefined" "Mitchell"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant