Image Shrinking

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Image Shrinking

Julián Grigera-3
Hi All,
   I'm using #shrinkBy:to: (from Image class) to scale down images.
   The comment on that method refers to a technique based on pixel
   interpolation that would improve the algorithm.
   has anyone already done this?

Thanks,
Julián

Reply | Threaded
Open this post in threaded view
|

RE: Image Shrinking

Wallen, David

It might be somewhere, in the contributed parcel for example.
See rotateByDegrees:to:interpolate: for an example of interpolating when source and destination images are the same general size. In that case, interpolating the four nearest source pixels isn't a bad idea.

But for reducing an image, I think the theory says that the optimal technique is to integrate over the entire "source region" for each corresponding destination pixel. That is, if your reduction is 8.6 to 1, then each destination pixel receives the average light content of a region 8.6 pixels square. So, partition the source image into the discrete contributing regions (just a grid), and average the contents of each to get a destination pixel.

Another way to achieve the same thing is to convolve the original image with a flat 9x9 image, where the outermost pixels are gray, and use a quick algorithm to reduce the resulting image. (The convolution produces an averaging filter.)

- Dave W

-----Original Message-----
From: Julián Grigera [mailto:[hidden email]]
Sent: Friday, March 30, 2007 9:21 AM
To: [hidden email]
Subject: Image Shrinking

Hi All,
   I'm using #shrinkBy:to: (from Image class) to scale down images.
   The comment on that method refers to a technique based on pixel
   interpolation that would improve the algorithm.
   has anyone already done this?

Thanks,
Julián

Reply | Threaded
Open this post in threaded view
|

RE: Image Shrinking

Steven Kelly
In reply to this post by Julián Grigera-3
> From: Julián Grigera [mailto:[hidden email]]
>    I'm using #shrinkBy:to: (from Image class) to scale down images.
>    The comment on that method refers to a technique based on pixel
>    interpolation that would improve the algorithm.
>    has anyone already done this?

I've used Michael Lucas-Smith's WinGDIPlusInterface from the public Store to get Windows GDI+ to do the hard work. The quality and speed is much better than you'd get with VW. Since I only need to do this for very small images, to pass them to GDI+ I just package them up as PNGs - the first lossless, compressed full-color format I could think of that both VW and Windows GDI+ support.

Image>>gdiShrunkenBy: scale
        | ws bigWinImage littleWinImage |
        ws := (ByteArray new: bits size // 4) writeStream.
        Refactory.PNG.PNGImageWriter writeImage: self on: ws.
        bigWinImage := Graphics.WinGDIPlus.GDIPlusBitmap fromBytes: ws contents.
        littleWinImage := bigWinImage shrunkenBy: scale.
        ^littleWinImage asNativeImage

You can get the PNG support by John Brant from http://www.refactory.com/Software/PNG.zip. As John said:
> From: John Brant [mailto:[hidden email]]
> Sent: Wednesday, October 02, 2002 18:41
> As for license, it is available for free use (commercial or otherwise)
> -- of course it is provided without any warranty. "

There's probably a much faster way than detouring through PNG, if you can figure it out (or if Michael can help!): get a drawing surface from GDI+ and draw the VW image on it.

I imagine it's also possible to do this all with Cairo, which would be platform independent (but would require an extra DLL/library to be installed).

HTH,
Steve

Reply | Threaded
Open this post in threaded view
|

Re: Image Shrinking

Michael Lucas-Smith-2
I didn't write that one.. but as soon as DLLCC can parse header files properly, I'll have a stab at putting the whole GDI+ API in as soon as possible.

On 31/03/07, Steven Kelly <[hidden email]> wrote:
> From: Julián Grigera [mailto:[hidden email]]
>    I'm using #shrinkBy:to: (from Image class) to scale down images.
>    The comment on that method refers to a technique based on pixel
>    interpolation that would improve the algorithm.
>    has anyone already done this?

I've used Michael Lucas-Smith's WinGDIPlusInterface from the public Store to get Windows GDI+ to do the hard work. The quality and speed is much better than you'd get with VW. Since I only need to do this for very small images, to pass them to GDI+ I just package them up as PNGs - the first lossless, compressed full-color format I could think of that both VW and Windows GDI+ support.

Image>>gdiShrunkenBy: scale
        | ws bigWinImage littleWinImage |
        ws := (ByteArray new: bits size // 4) writeStream.
        Refactory.PNG.PNGImageWriter writeImage: self on: ws.
        bigWinImage := Graphics.WinGDIPlus.GDIPlusBitmap fromBytes: ws contents.
        littleWinImage := bigWinImage shrunkenBy: scale.
        ^littleWinImage asNativeImage

You can get the PNG support by John Brant from http://www.refactory.com/Software/PNG.zip. As John said:
> From: John Brant [mailto:[hidden email]]
> Sent: Wednesday, October 02, 2002 18:41
> As for license, it is available for free use (commercial or otherwise)
> -- of course it is provided without any warranty. "

There's probably a much faster way than detouring through PNG, if you can figure it out (or if Michael can help!): get a drawing surface from GDI+ and draw the VW image on it.

I imagine it's also possible to do this all with Cairo, which would be platform independent (but would require an extra DLL/library to be installed).

HTH,
Steve


Reply | Threaded
Open this post in threaded view
|

Re[2]: Image Shrinking

Julián Grigera-2
In reply to this post by Steven Kelly
Steven, David,
        thanks a lot for your answers.
        Regretfully, I won't be able to use GDI+ since I must keep
        this application cross-platform.
        I will try with the region-averaging technique.
       
Best Regards,
Julián

>> From: Julián Grigera [mailto:[hidden email]]
>>    I'm using #shrinkBy:to: (from Image class) to scale down images.
>>    The comment on that method refers to a technique based on pixel
>>    interpolation that would improve the algorithm.
>>    has anyone already done this?

> I've used Michael Lucas-Smith's WinGDIPlusInterface from the
> public Store to get Windows GDI+ to do the hard work. The quality
> and speed is much better than you'd get with VW. Since I only need
> to do this for very small images, to pass them to GDI+ I just
> package them up as PNGs - the first lossless, compressed full-color
> format I could think of that both VW and Windows GDI+ support.

Image>>>gdiShrunkenBy: scale
> | ws bigWinImage littleWinImage |
> ws := (ByteArray new: bits size // 4) writeStream.
> Refactory.PNG.PNGImageWriter writeImage: self on: ws.
> bigWinImage := Graphics.WinGDIPlus.GDIPlusBitmap fromBytes: ws contents.
> littleWinImage := bigWinImage shrunkenBy: scale.
> ^littleWinImage asNativeImage

> You can get the PNG support by John Brant from
> http://www.refactory.com/Software/PNG.zip. As John said:
>> From: John Brant [mailto:[hidden email]]
>> Sent: Wednesday, October 02, 2002 18:41
>> As for license, it is available for free use (commercial or otherwise)
>> -- of course it is provided without any warranty. "

> There's probably a much faster way than detouring through PNG, if
> you can figure it out (or if Michael can help!): get a drawing
> surface from GDI+ and draw the VW image on it.

> I imagine it's also possible to do this all with Cairo, which
> would be platform independent (but would require an extra
> DLL/library to be installed).

> HTH,
> Steve


> __________ NOD32 2166 (20070403) Information __________

> This message was checked by NOD32 antivirus system.
> http://www.eset.com