Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2012-05

fpimage blur

10 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Mattias Gaertner

Hi,

Is there a function to blur an entire fpimage or a rectangular area?

Mattias

Mattias Gaertner
to Graeme Geldenhuys

Graeme Geldenhuys hat am 31. Mai 2012 um 12:59
geschrieben:

Show quoted text 9 lines
On 31 May 2012 09:06, Mattias Gaertner wrote: > Hi, > > Is there a function to blur an entire fpimage or a rectangular > area? Not a direct function of Tfpimage, but is very easily accomplished using fpcanvas and the various Interpolation methods.

Can you give an example or some pseudocode?

Mattias

Mattias Gaertner
to S.Anil Yilmaz

"S.Anil Yilmaz" hat am 31. Mai 2012 um 16:39
geschrieben:

Bgrabitmap for Lazarus has such filters as far as I know. You may use the algoritms I suppose.

Thanks.

It has some nice blur algorithms.

But as far as I can see:
BGRA is RGBA 8bit, I need up to 16 bit gray scale. FilterBlur allocates a copy of an image. I have big images, so I would like to avoid that.

FilterBlur seems to require runtime O(Width*Height*Radius^2). I need Radius 20, so this would be quite slow.

Mattias

Graeme Geldenhuys
to Mattias Gaertner: Graeme Geldenhuys hat am 31. Mai 2012 um 12:59 geschrieben: Can you give an example or…
Mattias Gaertner wrote
Can you give an example or some pseudocode?

I just moved country, so don't have access to my development pc yet (still in shipping), so can't get hold of a working code example. So best I can do is code example from memory... it was something like this.

Untested code follows...

------------------------
program project1;
{$mode objfpc}{$H+}
uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes, fpcanvas, fpimage, FPReadBMP, FPWriteBMP;
{$R *.res}
type
  { to make Initialize public, though FImage field variable is all we
need access to }
  TMyInterpolation = class(TMitchelInterpolation)
  public
    procedure Initialize(aimage: TFPCustomImage; acanvas: TFPCustomCanvas);
       override;
  end;
var
  img: TFPMemoryImage;
  inter: TMyInterpolation;

{ TMyInterpolation }

procedure TMyInterpolation.Initialize(aimage: TFPCustomImage;
  acanvas: TFPCustomCanvas);
begin
  inherited Initialize(aimage, acanvas);
end;
begin
  img := TFPMemoryImage.Create(32, 32);
  inter := TMyInterpolation.Create;
  try
    img.LoadFromFile('testin.bmp');
    inter.Initialize(img, nil);  { associate the memory image to
interpolation class }
    inter.Execute(0, 0, 32, 32);  { define rectangle or whole image
and exec interpolation }
    img.SaveToFile('testout.bmp');
  finally
    inter.Free;
    img.Free;
  end;
end.

-------------------------

I hope this gives you the general idea. As I mentioned, I have done something similar before, and from what I remember, it wasn't to hard to get working.

Alternatively, AggPas also has many filter/blur/interpolation functions available. There are a few AggPas demos showing this in action.

Regards,   - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://fpgui.sourceforge.net
Michael Van Canneyt
to Graeme Geldenhuys
Graeme Geldenhuys wrote 9 lines
On 31 May 2012 12:35, Mattias Gaertner wrote: > > Can you give an example or some pseudocode? I just moved country, so don't have access to my development pc yet (still in shipping), so can't get hold of a working code example. So best I can do is code example from memory... it was something like this.

You can find more examples in the ExtInterpolation.pp unit.

Michael.

Mattias Gaertner
to Graeme Geldenhuys: I just moved country, so don't have access to my development pc yet (still in shipping),…
Show quoted text 69 lines
On 31 May 2012 12:35, Mattias Gaertner wrote: > > Can you give an example or some pseudocode? I just moved country, so don't have access to my development pc yet (still in shipping), so can't get hold of a working code example. So best I can do is code example from memory... it was something like this. Untested code follows... ------------------------ program project1; {$mode objfpc}{$H+} uses {$IFDEF UNIX}{$IFDEF UseCThreads} cthreads, {$ENDIF}{$ENDIF} Classes, fpcanvas, fpimage, FPReadBMP, FPWriteBMP; {$R *.res} type { to make Initialize public, though FImage field variable is all we need access to } TMyInterpolation = class(TMitchelInterpolation) public procedure Initialize(aimage: TFPCustomImage; acanvas: TFPCustomCanvas); override; end; var img: TFPMemoryImage; inter: TMyInterpolation; { TMyInterpolation } procedure TMyInterpolation.Initialize(aimage: TFPCustomImage; acanvas: TFPCustomCanvas); begin inherited Initialize(aimage, acanvas); end; begin img := TFPMemoryImage.Create(32, 32); inter := TMyInterpolation.Create; try img.LoadFromFile('testin.bmp'); inter.Initialize(img, nil); { associate the memory image to interpolation class } inter.Execute(0, 0, 32, 32); { define rectangle or whole image and exec interpolation } img.SaveToFile('testout.bmp'); finally inter.Free; img.Free; end; end. ------------------------- I hope this gives you the general idea. As I mentioned, I have done something similar before, and from what I remember, it wasn't to hard to get working.

The interpolation is only for scaling, isn't it?
Do you mean: down sample, gaussian blur, up sample? That would give a fast algorithm, with only a small memory need. But I fear the results won't be pretty.

Alternatively, AggPas also has many filter/blur/interpolation functions available. There are a few AggPas demos showing this in action.

Yep, Aggpas seems to have the right algorithm.
Thanks, this gives me some ideas to continue.

Mattias

Mattias Gaertner
to Mattias Gaertner
Show quoted text 9 lines
On Thu, 31 May 2012 20:42:35 +0100 Graeme Geldenhuys wrote: [...] > Alternatively, AggPas also has many filter/blur/interpolation > functions available. There are a few AggPas demos showing this in > action. Yep, Aggpas seems to have the right algorithm. Thanks, this gives me some ideas to continue.

fpc has now a new unit fpimggauss, with a normal Gaussian blur and a fast binominal Gaussian blur.

Mattias