Upscaling algo discussion

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
User avatar
loupasc
Posts: 9
Joined: 2017-03-15T05:20:19-07:00
Authentication code: 1151

Upscaling algo discussion

Post by loupasc » 2017-03-27T05:21:59-07:00

Hi ImageMagick team,

First I present myself, quickly :) I do photograph and sometimes I print my picture; sizes can be up to 90x60cm. I discover ImageMagick just by chance. The first times I printed my picture I wasn't satisfied of the result after upscaling; then I looked for algorithms to upscale and google led me to ImageMagick.
Your soft gives good results. Filters like Mitchell and Lanczos work well but inevitably there are side-effects; side-effects are well represented by the map (http://www.imagemagick.org/Usage/img_di ... survey.gif) with aliasing/blocking/ringing/blurring.

I'm here because I'm also a software developer and I made my own implementation of the Directional Cubic Convolution Interpolation*
The result on the edge is quite good but I dislike the painty-look on the smooth part of the image; so I prefer to apply a classic bicubic on the smooth part.
You can download the corresponding archive (photoprocessor.zip) here: http://www.fraktales.net/logiciel/ which hosts my java application.

Or if you prefer I will add some examples.
This algorithm seems better because the dcci interpolation is done after (a quick) analysis of the image while a filter applies the same rule irregardless of the characteristic of the image.

I searched on the forum and I didn't see a topic discussing of this.

Finally I wrote this to ask you two questions, are you interested by this kind of upscaling ? and if yes, can I contribute to ImageMagick by adding this feature ?

Pascal

PS : Sorry for my english; please tell me if you don't understand something :-?

* wikipedia link: https://en.wikipedia.org/wiki/Direction ... erpolation
Where all men think alike, no one thinks very much. (Walter Lippmann)

User avatar
fmw42
Posts: 25764
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Upscaling algo discussion

Post by fmw42 » 2017-03-27T10:49:50-07:00

There has been some interest in this by other users and one of the IM developers is looking into this as time permits. We have been looking at the same Wikipedia link and also
http://www.ijarcce.com/upload/2013/dece ... ent_of.pdf

Imagemagick is coded in C. Is your code C or can you convert it to C?

I will forward this topic to the Imagemagick developer who is looking into this. He can reply in more detail.

snibgo
Posts: 12435
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Upscaling algo discussion

Post by snibgo » 2017-03-27T11:16:21-07:00

The ICBI results seem very impressive. I'd love to see this or similar in ImageMagick.
snibgo's IM pages: im.snibgo.com

User avatar
loupasc
Posts: 9
Joined: 2017-03-15T05:20:19-07:00
Authentication code: 1151

Re: Upscaling algo discussion

Post by loupasc » 2017-03-28T00:55:36-07:00

Hello fmw42,

The upscaler is implemented using Java; indeed I can convert it to C. I have to work deeper on the implementation because my current code is far from optimal (CPU and memory usage); but optimization can be done later :mrgreen:
I will have a look on the MagickWand C API in order to do a relevant conversion :)

@snibgo, yes results are quite good.
Where all men think alike, no one thinks very much. (Walter Lippmann)

User avatar
fmw42
Posts: 25764
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Upscaling algo discussion

Post by fmw42 » 2017-03-28T15:27:23-07:00

I have forwarded this topic to the Imagemagick developer. I expect he will respond or contact you when he has the time. He may be out of town right now.

User avatar
loupasc
Posts: 9
Joined: 2017-03-15T05:20:19-07:00
Authentication code: 1151

Re: Upscaling algo discussion

Post by loupasc » 2017-03-29T00:50:03-07:00

Ok, fine !
Where all men think alike, no one thinks very much. (Walter Lippmann)

User avatar
loupasc
Posts: 9
Joined: 2017-03-15T05:20:19-07:00
Authentication code: 1151

Re: Upscaling algo discussion

Post by loupasc » 2017-05-29T06:32:48-07:00

Where all men think alike, no one thinks very much. (Walter Lippmann)

User avatar
magick
Site Admin
Posts: 11100
Joined: 2003-05-31T11:32:55-07:00

Re: Upscaling algo discussion

Post by magick » 2017-05-29T15:25:48-07:00

Have you reviewed http://www.imagemagick.org/Usage/filter ... upsampling? If not, compare DCCI to his upsampling examples. If DCCI compares favorably, a basic version of the algorithm that works on a grayscale image in C would be useful. The C code would not rely on ImageMagick. Instead, we would port your C source to ImageMagick to support DCCI in a future release of ImageMagick.

User avatar
loupasc
Posts: 9
Joined: 2017-03-15T05:20:19-07:00
Authentication code: 1151

Re: Upscaling algo discussion

Post by loupasc » 2017-06-04T05:11:15-07:00

Below image samples 4x upsampled using my method and Sigmoidized version of Lanczos.

Image Image

Image Image

Image Image

Image Image

Image Image

Image Image
Where all men think alike, no one thinks very much. (Walter Lippmann)

User avatar
loupasc
Posts: 9
Joined: 2017-03-15T05:20:19-07:00
Authentication code: 1151

Re: Upscaling algo discussion

Post by loupasc » 2017-06-05T07:36:56-07:00

Hello magick,

The C code is now available, see http://www.fraktales.net/photoprocessor/source/
Upsample is performed by the applyDiamondUpscale function.

Code: Select all

inputs: 
 - width/height dimensions of the input image.
 - bitmap greyscale image represented by an array of unsigned char.
 - threshold value (%) used by edge detection.
output:
 - greyscale image represented by an array of unsigned char.
   output width = 2 * width, output height = 2 * height
byte* applyDiamondUpscale(int width, int height, byte* bitmap, byte threshold)
The border processing is not managed; I let you decide what to do in the border area of the image.

Application has been tested with 128x128 bitmap samples (cma128x128.bin, wizard128x128.bin) which contain a raw copy of the unsigned char array (no header).
Where all men think alike, no one thinks very much. (Walter Lippmann)

User avatar
magick
Site Admin
Posts: 11100
Joined: 2003-05-31T11:32:55-07:00

Re: Upscaling algo discussion

Post by magick » 2017-06-05T14:37:13-07:00

Thanks for the source code, it will be quite helpful in implementing the algorithm in ImageMagick. We'll look toward implementing the algorithm over the next month or so.

User avatar
loupasc
Posts: 9
Joined: 2017-03-15T05:20:19-07:00
Authentication code: 1151

Re: Upscaling algo discussion

Post by loupasc » 2017-06-06T01:02:48-07:00

Ok, I'm glad to make my contribution to ImageMagick and I will keep watching this topic in case you need something.
Where all men think alike, no one thinks very much. (Walter Lippmann)

User avatar
magick
Site Admin
Posts: 11100
Joined: 2003-05-31T11:32:55-07:00

Re: Upscaling algo discussion

Post by magick » 2017-06-12T18:09:55-07:00

Is the algorithm restricted to 2X upscaling? Does it not support arbitrary upscaling? Instead of 128x128 upscaling to 256x256, could the algorithm instead upscale to 400x400, as an example? If so, can you update the code base to support arbitrary widths and heights?

User avatar
fmw42
Posts: 25764
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Upscaling algo discussion

Post by fmw42 » 2017-06-12T19:05:03-07:00

loupasc wrote:
2017-06-04T05:11:15-07:00
Below image samples 4x upsampled using my method and Sigmoidized version of Lanczos.
Sorry, I may not be the best judge of this, but to my eyes, I do not see a significant improvement over the sigmoid approach. The only place that seems better in your method is in the dark green lines on the object in the upper right side of the first example. Am I missing other regions that are noticeably better?

Can you post your input images?

Did you implement https://en.wikipedia.org/wiki/Direction ... erpolation? If not, do you have a reference to what you implemented and did you try to implement from that link?

Have you seen:
http://www.ijarcce.com/upload/2013/dece ... ent_of.pdf
http://www.andreagiachetti.it/icbi/ (see links to code)

Those results look much more improved than standard upscaling using bicubics. Can and would you be interested in implementing the ICBI code?

User avatar
loupasc
Posts: 9
Joined: 2017-03-15T05:20:19-07:00
Authentication code: 1151

Re: Upscaling algo discussion

Post by loupasc » 2017-06-13T01:10:33-07:00

magick wrote:
2017-06-12T18:09:55-07:00
Is the algorithm restricted to 2X upscaling? Does it not support arbitrary upscaling? Instead of 128x128 upscaling to 256x256, could the algorithm instead upscale to 400x400, as an example? If so, can you update the code base to support arbitrary widths and heights?
Hello magick,

This upscaling method is restricted to double the image dimensions. If you want to get a 400x400 from a 128x128 one you have to combine this algorithm with another one.
fmw42 wrote:
2017-06-12T19:05:03-07:00
Sorry, I may not be the best judge of this, but to my eyes, I do not see a significant improvement over the sigmoid approach. The only place that seems better in your method is in the dark green lines on the object in the upper right side of the first example. Am I missing other regions that are noticeably better?

Can you post your input images?

Did you implement https://en.wikipedia.org/wiki/Direction ... erpolation? If not, do you have a reference to what you implemented and did you try to implement from that link?

Have you seen:
http://www.ijarcce.com/upload/2013/dece ... ent_of.pdf
http://www.andreagiachetti.it/icbi/ (see links to code)

Those results look much more improved than standard upscaling using bicubics. Can and would you be interested in implementing the ICBI code?
Hello fmw42,

I will highlight the part I prefer over the Sigmoid approach, but globally I think the sigmoid approach seems more aliased and more blurred than the algorithm I proposed.

Like I said in my first post, I did not implement exactly the algorithm described in the wikipedia because of too much paintly look of the image after upscale. I still use the gradient for edge detection but in the smooth part I prefer to stay to "classic bicubic" and for the second part of the method (finding horizontal/vertical lines) I prefer restrict the search on origin pixels and discard the previously computed diagonal ones:
- Square: original pixels
- Disc: previously interpolated pixels
Image
The pixel right the original one might be interpolated across the horizontal segment of four pixels.

Image
The pixel bottom the original one might be interpolated across the vertical segment of four pixels.

But I had a look on ICBI and I admit this is very good; so I should go deeper into this... :)

Thanks for your interest, I will come back to you with new elements to go forward.
Where all men think alike, no one thinks very much. (Walter Lippmann)

Post Reply