Reducing an Image

Reducing an Image

Post by Matt » Thu, 28 Dec 2000 11:37:23



Hi

I want to reduce the size of an image but I still want  the picture to look
the same. When I use Copyrect or BitBlt and sdhrink the image the image
becomes grainy.

Cheers

Matt

--------------------------------
 www.whamart.com
--------------------------------

 
 
 

Reducing an Image

Post by David J Taylo » Thu, 28 Dec 2000 06:47:53


Take a look at Earl Glynn's site:

  http://www.efg2.com/Lab/

Keywords resampling, interpolation.

David


> Hi

> I want to reduce the size of an image but I still want  the picture to
look
> the same. When I use Copyrect or BitBlt and sdhrink the image the image
> becomes grainy.

> Cheers

> Matt

> --------------------------------
>  www.whamart.com
> --------------------------------


 
 
 

Reducing an Image

Post by Matt » Thu, 28 Dec 2000 21:05:40


I couldn't find anything here. Great site, and I'm  already using a bitmap
rotation unit. But I couldn't find anything to do with reducing the size of
a bitmap and retain a good image with out the ditering problems.

--
Hi

Cheers

Matt

--------------------------------
 www.whamart.com
--------------------------------


> Take a look at Earl Glynn's site:

>   http://www.efg2.com/Lab/

> Keywords resampling, interpolation.

> David


> > Hi

> > I want to reduce the size of an image but I still want  the picture to
> look
> > the same. When I use Copyrect or BitBlt and sdhrink the image the image
> > becomes grainy.

> > Cheers

> > Matt

> > --------------------------------
> >  www.whamart.com
> > --------------------------------

 
 
 

Reducing an Image

Post by David J Taylo » Thu, 28 Dec 2000 18:40:47


Matt,

To be honest, neither could I, but I'm sure he has something...

Personally, I use the Intel Image processing libraries which do a
first-class job on resampling, with a variety of algorithms including the
super-sampling which is best if you have more than a 2:1 or so reduction.
Unless you're already using it in your code though, it may be overkill.

  http://developer.intel.com/software/products/perflib/ipl/index.htm

I seem to remember there being something on Anders Melander's site as
well...

David


> I couldn't find anything here. Great site, and I'm  already using a bitmap
> rotation unit. But I couldn't find anything to do with reducing the size
of
> a bitmap and retain a good image with out the ditering problems.

[]
 
 
 

Reducing an Image

Post by Sergej Katsman » Thu, 28 Dec 2000 21:05:56


Hi,
I have written a simple SuperSampling function.
It is simple and slow, but it could be a simple start for you.
You can use scanline or even assembler or  change it, so it can
manage not only quadratic images. I hope it is usefull for you.
The function works great with text, but some images became
 some kind of dull-colors, it seems as they became wrong palette ,
 if you solve this problem let me know.
{******************* Minimize *************************}
function Minimize(Source:TBitmap;factor:integer):TBitmap;
var
 x,y,i,j: Integer;
 r, g, b : Integer;
 tr, tg, tb, len : Integer;
begin
 Result:=TBitmap.Create;
 Result.PixelFormat:=Source.PixelFormat;
 Result.Width:=Source.Width div factor;
 Result.Height:=Source.Height div factor;

 len:=factor*factor;

 for x:=0 to Result.Width do
  begin
   for y:=0 to Result.Height do
    begin
    tr:=0;tg:=0;tb:=0;
     for i:=0 to factor-1 do
      for j:=0 to factor-1 do
       begin
         SeparateColor(Source.Canvas.Pixels[x*factor+j,y*factor+i],r,g,b);
         tr:=tr+(r div len);
         tg:=tg+(g div len);
         tb:=tb+(b div len);
       end;
       Result.Canvas.Pixels[x,y]:=RGB(tr,tg,tb);
    end;
   end;
end;
{RGB *************************}
function RGB(r, g, b : Integer) : TColor;
begin
    Result := r + 256 * (g + 256 * b);
end;
{SeparateColor *************************}
procedure SeparateColor(color : TColor; var r, g, b : Integer);
begin
    r := color Mod 256;
    g := (color Div 256) Mod 256;
    b := color Div 65536;
end;

 
 
 

Reducing an Image

Post by Rene Tschaggela » Thu, 28 Dec 2000 22:17:05


You are working with truecolor(24bit) images, aren't you ?

Rene
--
Ing.Buero R.Tschaggelar - http://www.ibrtses.com

 
 
 

Reducing an Image

Post by Matt » Fri, 29 Dec 2000 03:22:51


Yes...  and 256 colors

--
Hi

Cheers

Matt

--------------------------------
 www.whamart.com
--------------------------------

Quote:> You are working with truecolor(24bit) images, aren't you ?

> Rene
> --
> Ing.Buero R.Tschaggelar - http://www.ibrtses.com

 
 
 

Reducing an Image

Post by <magn.. » Fri, 29 Dec 2000 02:15:22


This is the routine I use for making thumbnails. It gives quite good
results. Feel free to use it.

procedure ShrinkPicture(src, dest: tBitmap;
  srcX1, srcY1, srcX2, srcY2: Integer;
  destX1, destY1, destX2, destY2: Integer);
type
  pRGBTripleArray = ^TRGBTripleArray;
  TRGBTripleArray = array[0..0] OF TRGBTriple;
var
  xscale, yscale : Single;
  destY, destX : Integer;
  x1, x2, y1, y2 : Integer;
  ix, iy : Integer;
  new_red, new_green : Integer;
  new_blue : Integer;
  totalRed, totalGreen, totalBlue : Single;
  ratio : Single;
  p0,p1 : pRGBTripleArray;
begin
  xscale := (destX2 - destX1 + 1) / (srcX2 - srcX1);
  yscale := (destY2 - destY1 + 1) / (srcY2 - srcY1);
  for destY := destY1 to destY2 do begin
    y1 := Trunc((destY - destY1) / yscale + srcY1);
    y2 := Trunc((destY + 1 - destY1) / yscale + srcY1) - 1;
    for destX := destX1 to destX2 do begin
      x1 := Trunc((destX - destX1) / xscale + srcX1);
      x2 := Trunc((destX + 1 - destX1) / xscale + srcX1) - 1;
      totalRed := 0;
      totalGreen := 0;
      totalBlue := 0;
      for iy := y1 to y2 do begin
        p0 := src.ScanLine[iy];
        for ix := x1 to x2 do begin
          totalRed   := totalRed  +p0[ix].rgbtRed;
          totalGreen := totalGreen+p0[ix].rgbtGreen;
          totalBlue  := totalBlue +p0[ix].rgbtBlue;
        end;
      end;
      ratio := 1/(x2-x1+1)/(y2-y1+1);
      p1 := dest.ScanLine[destY];
      p1[destX].rgbtRed   := Round(totalRed*ratio);
      p1[destX].rgbtGreen := Round(totalGreen*ratio);
      p1[destX].rgbtBlue  := Round(totalBlue*ratio);
    end;
  end;
end;

Enjoy!

-- RMK


Quote:> Hi

> I want to reduce the size of an image but I still want  the picture to
look
> the same. When I use Copyrect or BitBlt and sdhrink the image the image
> becomes grainy.

> Cheers

> Matt

> --------------------------------
>  www.whamart.com
> --------------------------------

 
 
 

Reducing an Image

Post by Rene Tschaggela » Fri, 29 Dec 2000 04:02:20


When you're averaging 256 color images, new colors that do not exist
may be required. As they are not there, it might look like artefacts.

Rene


> Yes...  and 256 colors



> > You are working with truecolor(24bit) images, aren't you ?

 
 
 

1. How to Reduce JPEG Image Size?

While browsing the Amazon.com Web site and checking
out the scanned color images of some books (tables of
content and covers), I noticed that their images were
scanned at 300dpi/24bits and the JPEG image files were
of very small size (typically 100-300KB).

Today, I scanned a color flyer (which was smaller than
8.5x11 sheet) from a local pizza shop and the image
size was a whopping 26MB !!! This does not make sense
to me.

Could somebody help me figure out how to reduce the
size of this huge JPEG image? Obviously, this problem
can be solved as evidenced by Amazon.com site. Thanks
a lot for helping.

John Smith

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

2. TreeView

3. Reducing TARGA images

4. Where can i find libglut.a

5. Reducing TARGA images to 256 colors: cheap method needed

6. HTML without networks?

7. Reducing an image's resolution?

8. CosmoGL / Cosmo3D - details?

9. Reducing 1600x1200 image for 5x7,4x6 prints?

10. HELP : How to reduce an image size, not the quality

11. Reduce an Image Color to any number of colors [URGENT]

12. StretchDraw to reduce an image;

13. Best Algorithm For Reducing An Image to 1/4 Of Its Size????