Recent

Author Topic: Edge detection  (Read 5111 times)

liewald

  • Full Member
  • ***
  • Posts: 142
Edge detection
« on: January 27, 2019, 01:04:50 pm »
Anyone know of a lazarus based working sobel filter to work on either a tbitmap or a tbitmap32

thanks in advance


engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Edge detection
« Reply #1 on: January 27, 2019, 05:31:40 pm »
For TImage32, check unit G32_WConvolution:
Quote
     *   28_02_2003 added procedure DoSobel( Dst, Src: TBitmap32);       *

liewald

  • Full Member
  • ***
  • Posts: 142
Re: Edge detection
« Reply #2 on: January 27, 2019, 05:47:59 pm »
Sorry but I cant find that unit anywhere in graphics32

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Edge detection
« Reply #3 on: January 27, 2019, 06:04:52 pm »
Attached.

liewald

  • Full Member
  • ***
  • Posts: 142
Re: Edge detection
« Reply #4 on: January 27, 2019, 06:29:57 pm »
Sorry seems to be incompatible with newer Graphics32.

Fixed an asm call but it seems that redcomponent etc have changed to a tcolor32  from a tcolor32array and it's killing it and because I dont know the algorithm I haven' t got a clue where to start a fix


Compile Project, Target: Imgover.exe: Exit code 1, Errors: 50, Hints: 48
g32_wconvolution.pas(216,31) Error: Incompatible type for arg no. 1: Got "TColor32Array", expected "TColor32"
GR32.pas(1265,10) Hint: Found declaration: RedComponent(TColor32):LongInt;
g32_wconvolution.pas(216,61) Error: Incompatible type for arg no. 1: Got "TColor32Array", expected "TColor32"
GR32.pas(1265,10) Hint: Found declaration: RedComponent(TColor32):LongInt;
g32_wconvolution.pas(216,93) Error: Incompatible type for arg no. 1: Got "TColor32Array", expected "TColor32"
GR32.pas(1265,10) Hint: Found declaration: RedComponent(TColor32):LongInt;
g32_wconvolution.pas(217,31) Error: Incompatible type for arg no. 1: Got "TColor32Array", expected "TColor32"
GR32.pas(1265,10) Hint: Found declaration: RedComponent(TColor32):LongInt;
g32_wconvolution.pas(217,61) Error: Incompatible type for arg no. 1: Got "TColor32Array", expected "TColor32"
GR32.pas(1265,10) Hint: Found declaration: RedComponent(TColor32):LongInt;
g32_wconvolution.pas(217,93) Error: Incompatible type for arg no. 1: Got "TColor32Array", expected "TColor32"
GR32.pas(1265,10) Hint: Found declaration: RedComponent(TColor32):LongInt;
g32_wconvolution.pas(218,31) Error: Incompatible type for arg no. 1: Got "TColor32Array", expected "TColor32"
GR32.pas(1265,10) Hint: Found declaration: RedComponent(TColor32):LongInt;
g32_wconvolution.pas(218,61) Error: Incompatible type for arg no. 1: Got "TColor32Array", expected "TColor32"
GR32.pas(1265,10) Hint: Found declaration: RedComponent(TColor32):LongInt;
g32_wconvolution.pas(218,93) Error: Incompatible type for arg no. 1: Got "TColor32Array", expected "TColor32"
GR32.pas(1265,10) Hint: Found declaration: RedComponent(TColor32):LongInt;
g32_wconvolution.pas(223,33) Error: Incompatible type for arg no. 1: Got "TColor32Array", expected "TColor32"
GR32.pas(1270,10) Hint: Found declaration: GreenComponent(TColor32):LongInt;
g32_wconvolution.pas(223,65) Error: Incompatible type for arg no. 1: Got "TColor32Array", expected "TColor32"
GR32.pas(1270,10) Hint: Found declaration: GreenComponent(TColor32):LongInt;
g32_wconvolution.pas(223,99) Error: Incompatible type for arg no. 1: Got "TColor32Array", expected "TColor32"
GR32.pas(1270,10) Hint: Found declaration: GreenComponent(TColor32):LongInt;
g32_wconvolution.pas(224,33) Error: Incompatible type for arg no. 1: Got "TColor32Array", expected "TColor32"
GR32.pas(1270,10) Hint: Found declaration: GreenComponent(TColor32):LongInt;
g32_wconvolution.pas(224,65) Error: Incompatible type for arg no. 1: Got "TColor32Array", expected "TColor32"
GR32.pas(1270,10) Hint: Found declaration: GreenComponent(TColor32):LongInt;
g32_wconvolution.pas(224,99) Error: Incompatible type for arg no. 1: Got "TColor32Array", expected "TColor32"
GR32.pas(1270,10) Hint: Found declaration: GreenComponent(TColor32):LongInt;
g32_wconvolution.pas(225,33) Error: Incompatible type for arg no. 1: Got "TColor32Array", expected "TColor32"
GR32.pas(1270,10) Hint: Found declaration: GreenComponent(TColor32):LongInt;
g32_wconvolution.pas(225,65) Error: Incompatible type for arg no. 1: Got "TColor32Array", expected "TColor32"
GR32.pas(1270,10) Hint: Found declaration: GreenComponent(TColor32):LongInt;
g32_wconvolution.pas(225,99) Error: Incompatible type for arg no. 1: Got "TColor32Array", expected "TColor32"
GR32.pas(1270,10) Hint: Found declaration: GreenComponent(TColor32):LongInt;
g32_wconvolution.pas(230,32) Error: Incompatible type for arg no. 1: Got "TColor32Array", expected "TColor32"
GR32.pas(1275,10) Hint: Found declaration: BlueComponent(TColor32):LongInt;
g32_wconvolution.pas(230,63) Error: Incompatible type for arg no. 1: Got "TColor32Array", expected "TColor32"
GR32.pas(1275,10) Hint: Found declaration: BlueComponent(TColor32):LongInt;
g32_wconvolution.pas(230,96) Error: Incompatible type for arg no. 1: Got "TColor32Array", expected "TColor32"
GR32.pas(1275,10) Hint: Found declaration: BlueComponent(TColor32):LongInt;
g32_wconvolution.pas(231,32) Error: Incompatible type for arg no. 1: Got "TColor32Array", expected "TColor32"
GR32.pas(1275,10) Hint: Found declaration: BlueComponent(TColor32):LongInt;
g32_wconvolution.pas(231,63) Error: Incompatible type for arg no. 1: Got "TColor32Array", expected "TColor32"
GR32.pas(1275,10) Hint: Found declaration: BlueComponent(TColor32):LongInt;
g32_wconvolution.pas(231,96) Error: Incompatible type for arg no. 1: Got "TColor32Array", expected "TColor32"
GR32.pas(1275,10) Hint: Found declaration: BlueComponent(TColor32):LongInt;
g32_wconvolution.pas(232,32) Error: Incompatible type for arg no. 1: Got "TColor32Array", expected "TColor32"
GR32.pas(1275,10) Hint: Found declaration: BlueComponent(TColor32):LongInt;
g32_wconvolution.pas(232,63) Error: Incompatible type for arg no. 1: Got "TColor32Array", expected "TColor32"
GR32.pas(1275,10) Hint: Found declaration: BlueComponent(TColor32):LongInt;
g32_wconvolution.pas(232,96) Error: Incompatible type for arg no. 1: Got "TColor32Array", expected "TColor32"
GR32.pas(1275,10) Hint: Found declaration: BlueComponent(TColor32):LongInt;
g32_wconvolution.pas(235,13) Error: Incompatible types: got "TColor32" expected "TColor32Array"
g32_wconvolution.pas(270,21) Error: Incompatible type for arg no. 1: Got "TColor32Array", expected "TColor32"
GR32.pas(1265,10) Hint: Found declaration: RedComponent(TColor32):LongInt;
g32_wconvolution.pas(270,52) Error: Incompatible type for arg no. 1: Got "TColor32Array", expected "TColor32"
GR32.pas(1265,10) Hint: Found declaration: RedComponent(TColor32):LongInt;
g32_wconvolution.pas(270,81) Error: Incompatible type for arg no. 1: Got "TColor32Array", expected "TColor32"
GR32.pas(1265,10) Hint: Found declaration: RedComponent(TColor32):LongInt;
g32_wconvolution.pas(270,112) Error: Incompatible type for arg no. 1: Got "TColor32Array", expected "TColor32"
GR32.pas(1265,10) Hint: Found declaration: RedComponent(TColor32):LongInt;
g32_wconvolution.pas(270,143) Error: Incompatible type for arg no. 1: Got "TColor32Array", expected "TColor32"
GR32.pas(1265,10) Hint: Found declaration: RedComponent(TColor32):LongInt;
g32_wconvolution.pas(271,21) Error: Incompatible type for arg no. 1: Got "TColor32Array", expected "TColor32"
GR32.pas(1265,10) Hint: Found declaration: RedComponent(TColor32):LongInt;
g32_wconvolution.pas(271,52) Error: Incompatible type for arg no. 1: Got "TColor32Array", expected "TColor32"
GR32.pas(1265,10) Hint: Found declaration: RedComponent(TColor32):LongInt;
g32_wconvolution.pas(271,81) Error: Incompatible type for arg no. 1: Got "TColor32Array", expected "TColor32"
GR32.pas(1265,10) Hint: Found declaration: RedComponent(TColor32):LongInt;
g32_wconvolution.pas(271,112) Error: Incompatible type for arg no. 1: Got "TColor32Array", expected "TColor32"
GR32.pas(1265,10) Hint: Found declaration: RedComponent(TColor32):LongInt;
g32_wconvolution.pas(271,143) Error: Incompatible type for arg no. 1: Got "TColor32Array", expected "TColor32"
GR32.pas(1265,10) Hint: Found declaration: RedComponent(TColor32):LongInt;
g32_wconvolution.pas(272,21) Error: Incompatible type for arg no. 1: Got "TColor32Array", expected "TColor32"
GR32.pas(1265,10) Hint: Found declaration: RedComponent(TColor32):LongInt;
g32_wconvolution.pas(272,52) Error: Incompatible type for arg no. 1: Got "TColor32Array", expected "TColor32"
GR32.pas(1265,10) Hint: Found declaration: RedComponent(TColor32):LongInt;
g32_wconvolution.pas(272,81) Error: Incompatible type for arg no. 1: Got "TColor32Array", expected "TColor32"
GR32.pas(1265,10) Hint: Found declaration: RedComponent(TColor32):LongInt;
g32_wconvolution.pas(272,112) Error: Incompatible type for arg no. 1: Got "TColor32Array", expected "TColor32"
GR32.pas(1265,10) Hint: Found declaration: RedComponent(TColor32):LongInt;
g32_wconvolution.pas(272,143) Error: Incompatible type for arg no. 1: Got "TColor32Array", expected "TColor32"
GR32.pas(1265,10) Hint: Found declaration: RedComponent(TColor32):LongInt;
g32_wconvolution.pas(273,21) Error: Incompatible type for arg no. 1: Got "TColor32Array", expected "TColor32"
GR32.pas(1265,10) Hint: Found declaration: RedComponent(TColor32):LongInt;
g32_wconvolution.pas(273,52) Error: Incompatible type for arg no. 1: Got "TColor32Array", expected "TColor32"
GR32.pas(1265,10) Hint: Found declaration: RedComponent(TColor32):LongInt;
g32_wconvolution.pas(273,81) Error: Incompatible type for arg no. 1: Got "TColor32Array", expected "TColor32"
GR32.pas(1265,10) Hint: Found declaration: RedComponent(TColor32):LongInt;
g32_wconvolution.pas(273,112) Error: Incompatible type for arg no. 1: Got "TColor32Array", expected "TColor32"
GR32.pas(1265,10) Hint: Found declaration: RedComponent(TColor32):LongInt;
g32_wconvolution.pas(273,143) Error: Incompatible type for arg no. 1: Got "TColor32Array", expected "TColor32"
GR32.pas(1265,10) Hint: Found declaration: RedComponent(TColor32):LongInt;
g32_wconvolution.pas(274,21) Error: Incompatible type for arg no. 1: Got "TColor32Array", expected "TColor32"
GR32.pas(1265,10) Hint: Found declaration: RedComponent(TColor32):LongInt;
g32_wconvolution.pas(274,52) Error: Incompatible type for arg no. 1: Got "TColor32Array", expected "TColor32"

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11452
  • FPC developer.
Re: Edge detection
« Reply #5 on: January 27, 2019, 06:47:28 pm »
That looks horrible primitive, no SSE/AVX, and multipass(which hurts for large images, since then they are not cached)

There are heaps of assembler versions. In my delphi software I use simd(lib), compiled into a DLL. (https://sourceforge.net/projects/simd/files/  there are versions on github also)

I still planned to do sobel myself, but the relevant projects have been put on ice.

(to save time for production I also usually only do 64-bit and aligned images)
« Last Edit: January 28, 2019, 04:50:13 pm by marcov »

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Edge detection
« Reply #6 on: January 27, 2019, 07:30:57 pm »
Guys, the file is from "28_02_2003".

liewald

  • Full Member
  • ***
  • Posts: 142
Re: Edge detection
« Reply #7 on: January 27, 2019, 07:35:46 pm »
Yup..........

Loosing hair rapidly!!!!!


liewald

  • Full Member
  • ***
  • Posts: 142
Re: Edge detection
« Reply #8 on: January 28, 2019, 03:36:20 pm »
Where there's a will there's a way

Thanks all managed without graphics32

procedure TForm1.Button3Click(Sender: TObject);
var bmp :  TBGRABitmap;
begin
     bmp:=TBGRABitmap.create(image.Picture.Bitmap);
    bmp.assign(bmp.FilterContour);
    image.Picture.Bitmap.Assign(bmp.Bitmap);
    bmp.Free;
end

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: Edge detection
« Reply #9 on: January 28, 2019, 08:29:59 pm »
I'm fairly sure TBGRABitmap.FilterContour is not identical to Sobel, but if it works for you that does not matter.
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

liewald

  • Full Member
  • ***
  • Posts: 142
Re: Edge detection
« Reply #10 on: January 29, 2019, 10:38:54 am »
Yup not the same but it achieves what I need :D

would prefer sobel or canny but not worth the time or pain to develop :D

I'm a lazy git at heart :D

circular

  • Hero Member
  • *****
  • Posts: 4220
    • Personal webpage
Re: Edge detection
« Reply #11 on: January 29, 2019, 04:56:49 pm »
Replace
Code: Delphi  [Select][+][-]
  1.    bmp.assign(bmp.FilterContour);
By
Code: Delphi  [Select][+][-]
  1.    BGRAReplace(bmp, bmp.FilterContour);
To avoid memory leak

Note : FilterContour is not strictly speaking a Sobel filter but is also based on a 3x3 matrix.
Conscience is the debugger of the mind

liewald

  • Full Member
  • ***
  • Posts: 142
Re: Edge detection
« Reply #12 on: January 30, 2019, 10:47:46 am »
thanks

 

TinyPortal © 2005-2018