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

Mailing lists / fpc-pascal / 2012-05
10 messages · 5 people · –
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
Hi,
Is there a function to blur an entire fpimage or a rectangular area?
Mattias
Not to my knowledge.
Michael.
Is there a function to blur an entire fpimage or a rectangular area? Mattias
Mattias Gaertner wroteHi, 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.
Graeme Geldenhuys hat am 31. Mai 2012 um 12:59
geschrieben:
Can you give an example or some pseudocode?
Mattias
Is there a function to blur an entire fpimage or a rectangular area? Mattias
Bgrabitmap for Lazarus has such filters as far as I know. You may use the algoritms I suppose.
"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 hat am 31. Mai 2012 um 12:59 geschrieben: Can you give an example or…
Mattias Gaertner wroteCan 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.
You can find more examples in the ExtInterpolation.pp unit.
Michael.
I just moved country, so don't have access to my development pc yet (still in shipping),…
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
fpc has now a new unit fpimggauss, with a normal Gaussian blur and a fast binominal Gaussian blur.
Mattias