resize methods

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
voirin
Posts: 2
Joined: 2012-01-17T09:03:32-07:00
Authentication code: 8675308

resize methods

Post by voirin »

Hi, I am new to magick++ having just recently compiled it under VS2010. I am trying to get my head around the various resize methods as the documentation seems a little unclear about things. For example, in the Magick::Image Class documentation page it mentions that the 'filterType' function specifies the "Filter to use when resizing image" but does not mention the resize method to use.

I noticed that the Magick::Image Class contains three resize methods: sample(), scale(), and zoom().

There are also 15 filter types which can be applied via the filterType() function e.g. PointFilter, BoxFilter, TriangleFilter, LanczosFilter etc.

My questions are:

1. Is zoom() dependent on the filter type used?

2. I guess if filterType() isn't used, zoom() uses Lanczos by default?

3. sample() and scale() seem independent of filter type, as sample() uses pixel sampling algorithm and scale() uses simple ratio algorithm? Are these special kinds of 'filters' outside the scope of FilterType enumerations?

4. There are various commandline filters like Kaiser, Bartlett, Parzen, Welshand and Bohman that don't appear in the magick++ filter types. Am I missing something?

Just trying to encapsulate all resize methods and filters available within magick++ to perform testing under c++.

Many thanks for any help.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: resize methods

Post by anthony »

'zoom' is actually an filtered resize algorthm name invented by Professor Paul Heckbert, and from which almost ALL image resize program base their image resizeing.
See the Resize Filter Introduction at...
http://www.imagemagick.org/Usage/resize/#filter

zoom() is a depreciated alias for resize(), you should use the latter.

sample() is essentially a 'nearest neighbour' or 'point' filter resize
scale is a 'averaging' or 'box' filter resize.
These are just FASTER versions that make direct use of the 'simple' filter method rather than actually look up a filter weighting scheme based on complex mathematical functions.

Actually you can get far more information about Resize and the Filters from the Command Line Examples,
http://www.imagemagick.org/Usage/resize/
All the command line operators map directly to the API methods.

It also details all the filter types (their are more than 15! and many expert option variations too) and what they do to the image. It took me a long time to come to grips with all the info, so I created a summery of what I learnt.

If you like to delve in deeper, large volumes of chatter about filters are in the "Digital Image Processing" forum, and not just in ImageMagick but also other packages (mostly VIPS)
viewforum.php?f=22

Note the CLI (command line) API uses the 'image geometry argument' to work out the actual final image and attempt to preserve aspect ratio, before it makes the call. Some other API's do not do this! I do not know if Magick::Image Class does or not.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
voirin
Posts: 2
Joined: 2012-01-17T09:03:32-07:00
Authentication code: 8675308

Re: resize methods

Post by voirin »

Thanks for the reply - very helpful and much appreciated!

I never knew about the resize() function as the Magick++ documentation makes no mention of it at all. It still refers to the old zoom(). Am I looking in the right place? http://www.imagemagick.org/Magick++/Image.html. Maybe the documentation hasn't been updated?

I was also looking at the filter types available through the CLI via "convert -list filter" and noticed 26 filters available. But for some reason I cannot gain access to all of them via Magick++ API e.g. Welsh, Jinc, Lanczos2 etc. Are these only available via CLI and not via Magick++ API?

Thanks for any help on this.
Steve_
Posts: 6
Joined: 2015-10-18T08:39:23-07:00
Authentication code: 1151

Re: resize methods

Post by Steve_ »

Hi, I'm trying the MagickResizeImage api, which works well, but I have a couple of questions:

1. I'm wondering if it is appropriate for zooming as it's actually changing the image contained in ImageMagic. I would have thought that zooming should be a temporary screen effect only. You could reload the image again from the file afterwards I suppose, but you would lose any other work that has been done on the image.
2. This sort of relates to the first question: when you zoom out (make the image look smaller) and then zoom in again (make it larger) the image resolution is lost. Again, how do you get around this problem without starting again and reloading the image from scratch?

Many thanks, Steve.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: resize methods

Post by snibgo »

The MagickWand function MagickResizeImage() modifies an image. MagicWand has no concept of "temporary screen effect only". That would be a feature of a screen editor that might use ImageMagick. The editor might have a "zoom" function for display purposes only as well as a "resize" option to change the image. These might use the same IM function, but in different ways; the "zoom" function would use a temporary copy of the image.
snibgo's IM pages: im.snibgo.com
Steve_
Posts: 6
Joined: 2015-10-18T08:39:23-07:00
Authentication code: 1151

Re: resize methods

Post by Steve_ »

Ok that's great snibgo. Many thanks.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: resize methods

Post by anthony »

Generally applications (even command line) would 'clone' the image that is being resized, to preserve the original.

For a command line example see...
http://www.imagemagick.org/Usage/files/#write
Though the methdo is equally valid in any API you would use.

Note that clone actually does not copy the data unless that data is changed. So when resizing an image smaller, you don't actually use twice as much space.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply