'seeding matrix (7:1) x (1:7)
DIM a%(-3 TO 3)
a%(-3) = 1: a%(-2) = 2: a%(-1) = 4: a%(0) = 8: a%(1) = 4: a%(2) = 2: a%(3) = 1
'alpha multiplier matrix kernel (7:7)
DIM kern%(LBOUND(a%) TO UBOUND(a%), LBOUND(a%) TO UBOUND(a%))
FOR x% = LBOUND(kern%, 1) TO UBOUND(kern%, 1) ' iterate kernel matrix columns
FOR y% = LBOUND(kern%, 2) TO UBOUND(kern%, 2) ' iterate kernel matrix rows
kern%(x%, y%) = a%(x%) * a%(y%) ' seed the gaussian kernel position
NEXT y%, x%
mult! = 255 / kern%(0, 0) ' set a multiplier to prevent alpha bleed through
'display clear image, create and display blurred image
_PUTIMAGE (1, 1), b& ' place clear bird image on left of mainscreen
FOR ox% = 0 TO _WIDTH(b&) - 1 '
FOR oy% = 0 TO _HEIGHT(b&) - 1 '
_SOURCE b& ' source: clear bird image
c~& = POINT(ox%, oy%) ' get source pixel color at (ox%, oy%)
_DEST r& ' destination: blurred receiving image
FOR x% = LBOUND(kern%, 1) TO UBOUND(kern%, 1) ' apply the alpha matrix around original point
FOR y% = LBOUND(kern%, 2) TO UBOUND(kern%, 2)
PSET (ox% + x%, oy% + y%), _RGBA32(_RED32(c~&), _GREEN32(c~&), _BLUE32(c~&), mult! * kern%(x%, y%))
NEXT y%, x%
NEXT oy%, ox%
_DEST 0 ' destination back to mainscreen
_PUTIMAGE (_WIDTH(0) - _WIDTH(r&) - 2, 1), r& ' place blurred receiving image on right of mainscreen
END
07-26-2023, 02:25 PM (This post was last modified: 07-26-2023, 02:26 PM by TerryRitchie.)
I modified RhoSigma's ApplyFilter& function from his Image Processing Library (imageprocess.bm) to only perform Gaussian blurs in the laser project I'm working on. Here is the result:
Nice Function, Terry. The _MEM stuff sure makes a speed increase. I think I will try to incorporate _MEM in mine to see how much faster it can get. Well, here's what I came up with after studying sources in other languages. This one let's you define the radius, higher values make it slower.
- Dav
Code: (Select All)
Screen_NewImage(800, 600, 32)
For t = 1To1000
size = Rnd * 255
x = Rnd * _Width: y = Rnd * _Height
Line (x, y)-(x + size, y + size), _RGB(Rnd * 255, Rnd * 255, Rnd * 255), BF
(07-26-2023, 02:25 PM)TerryRitchie Wrote: I modified RhoSigma's ApplyFilter& function from his Image Processing Library (imageprocess.bm) to only perform Gaussian blurs in the laser project I'm working on. Here is the result:
You made a nice compact function out of it @TerryRitchie, you could replace the _NEWIMAGE/_PUTIMAGE combo in the "Copy the source image" section with _COPYIMAGE instead.
The reason to use that combo was at the time of writing my image processing library _COPYIMAGE had a bug in conjunction with _MEMIMAGE. It simply also copied the memory lock esteblished by _MEMIMAGE to the new image. This caused a problem when you _FREEIMAGEed either the original/copied image and after that freeing the other one. Because both images shared the same memory lock, which was freed with the first image, you cause a module error when freing the second one and the memory lock did no longer exist. The _NEWIMAGE/_PUTIMAGE combo was a safe workaround, however _COPYIMAGE has been fixed in QB64 v1.4
(07-26-2023, 06:24 PM)Dav Wrote: Nice Function, Terry. The _MEM stuff sure makes a speed increase. I think I will try to incorporate _MEM in mine to see how much faster it can get. Well, here's what I came up with after studying sources in other languages. This one let's you define the radius, higher values make it slower.
- Dav
Code: (Select All)
Screen_NewImage(800, 600, 32)
For t = 1To1000
size = Rnd * 255
x = Rnd * _Width: y = Rnd * _Height
Line (x, y)-(x + size, y + size), _RGB(Rnd * 255, Rnd * 255, Rnd * 255), BF
(07-26-2023, 02:25 PM)TerryRitchie Wrote: I modified RhoSigma's ApplyFilter& function from his Image Processing Library (imageprocess.bm) to only perform Gaussian blurs in the laser project I'm working on. Here is the result:
You made a nice compact function out of it @TerryRitchie, you could replace the _NEWIMAGE/_PUTIMAGE combo in the "Copy the source image" section with _COPYIMAGE instead.
The reason to use that combo was at the time of writing my image processing library _COPYIMAGE had a bug in conjunction with _MEMIMAGE. It simply also copied the memory lock esteblished by _MEMIMAGE to the new image. This caused a problem when you _FREEIMAGEed either the original/copied image and after that freeing the other one. Because both images shared the same memory lock, which was freed with the first image, you cause a module error when freing the second one and the memory lock did no longer exist. The _NEWIMAGE/_PUTIMAGE combo was a safe workaround, however _COPYIMAGE has been fixed in QB64 v1.4
I was wondering why _COPYIMAGE was not used in favor of _PUTIMAGE when I was reworking the code. I'll make that change then. Thanks for the information.
By the way, your libraries are a wealth of knowledge. Thank you for sharing them. It wasn't until I needed your image processing library that I started snooping around in the rest of your libraries. Good stuff!
Software and cathedrals are much the same — first we build them, then we pray. QB64 Tutorial
07-26-2023, 09:08 PM (This post was last modified: 07-26-2023, 09:08 PM by RhoSigma.)
(07-26-2023, 07:00 PM)TerryRitchie Wrote: By the way, your libraries are a wealth of knowledge. Thank you for sharing them.
Thanks and Your welcome, it's good to know the stuff has some value for other people too.
(07-26-2023, 07:00 PM)TerryRitchie Wrote: It wasn't until I needed your image processing library that I started snooping around in the rest of your libraries. Good stuff!
(07-26-2023, 01:57 PM)bplus Wrote: Can you get an algo that goes the other way? I see enough blur already.
Yep, the ApplyFilter&() function of my imageprocess.bm library has also some "sharpen" filters as well as line/edge detect filters and some artistic ones.