improved high quality image downscaling

If you have a cool piece of software to share, but you are not hosting it officially yet, please dump it in here. If you have code snippets that are useful, please donate!
Post Reply
Peer Sommerlund
Knows some wx things
Knows some wx things
Posts: 43
Joined: Tue Jun 13, 2006 7:21 am
Location: Denmark
Contact:

improved high quality image downscaling

Post by Peer Sommerlund » Mon May 21, 2007 1:34 pm

Hello.

The following patch to the image sample shows a different method for downscaling images, that provides a higher quality image than "high quality" scaling.

Regards,
Peer
Attachments
image-sample-patch.txt
Unified diff against image sample
(10.24 KiB) Downloaded 131 times

User avatar
tierra
Site Admin
Site Admin
Posts: 1340
Joined: Sun Aug 29, 2004 7:14 pm
Location: Salt Lake City, Utah, USA
Contact:

Post by tierra » Mon May 21, 2007 3:15 pm

What kind of algorithm does this use and how does it compare to wxIMAGE_QUALITY_HIGH in regards to speed when either upsampling or downsampling?

Peer Sommerlund
Knows some wx things
Knows some wx things
Posts: 43
Joined: Tue Jun 13, 2006 7:21 am
Location: Denmark
Contact:

Post by Peer Sommerlund » Mon May 21, 2007 7:53 pm

The algorithm only works for downscaling. It is slower than wxIMAGE_QUALITY_HIGH, since it uses float math. (wxIMAGE_QUALITY_HIGH is blur + sample which is integer math only)

The process is simple: For each target pixel, compute the average colour of the corresponding area on the source image. Note that this may include fractions of pixels.

Example:

Source image:

Code: Select all

+---+---+
|   |   |
+---+---+
|   |   |
+---+---+
With target pixel area overlayed:

Code: Select all

+---+---+
|  TTTT |
+--TTTT-+
|  TTTT |
+---+---+
thus the two rightmost pixels of the source image contribute more than the two leftmost pixels.

Please note that the code has not been optimized so it may be possible to reorganise to get more speed, but it will always be slower than wxIMAGE_QUALITY_HIGH.

Post Reply