Page 1 of 2

Upscaling algo discussion

Posted: 2017-03-27T05:21:59-07:00
by loupasc
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

Re: Upscaling algo discussion

Posted: 2017-03-27T10:49:50-07:00
by fmw42
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.

Re: Upscaling algo discussion

Posted: 2017-03-27T11:16:21-07:00
by snibgo
The ICBI results seem very impressive. I'd love to see this or similar in ImageMagick.

Re: Upscaling algo discussion

Posted: 2017-03-28T00:55:36-07:00
by loupasc
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.

Re: Upscaling algo discussion

Posted: 2017-03-28T15:27:23-07:00
by fmw42
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.

Re: Upscaling algo discussion

Posted: 2017-03-29T00:50:03-07:00
by loupasc
Ok, fine !

Re: Upscaling algo discussion

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

Re: Upscaling algo discussion

Posted: 2017-05-29T15:25:48-07:00
by magick
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.

Re: Upscaling algo discussion

Posted: 2017-06-04T05:11:15-07:00
by loupasc
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

Re: Upscaling algo discussion

Posted: 2017-06-05T07:36:56-07:00
by loupasc
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).

Re: Upscaling algo discussion

Posted: 2017-06-05T14:37:13-07:00
by magick
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.

Re: Upscaling algo discussion

Posted: 2017-06-06T01:02:48-07:00
by loupasc
Ok, I'm glad to make my contribution to ImageMagick and I will keep watching this topic in case you need something.

Re: Upscaling algo discussion

Posted: 2017-06-12T18:09:55-07:00
by magick
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?

Re: Upscaling algo discussion

Posted: 2017-06-12T19:05:03-07:00
by fmw42
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?

Re: Upscaling algo discussion

Posted: 2017-06-13T01:10:33-07:00
by loupasc
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.