Recent

Author Topic: Splitting Picture into Quads using Quadtree ?  (Read 1121 times)

Boleeman

  • Hero Member
  • *****
  • Posts: 1158
Splitting Picture into Quads using Quadtree ?
« on: April 06, 2026, 06:58:00 am »
Was wondering if anyone has been able to use Lazarus to visually split a loaded picture into Quads using Quadtree (as shown in attachments) ?

There are plenty of Python and C++ codes, but nothing much in Lazarus (Pascal) or Delphi.

Corpsman had an example of compressing a grayscale bmp image using the Quadtree Algorithm, but I wanted to load a color png and have it dissected into quads using Quadtree.

Here are some nice Python implementations:
https://github.com/AlexEidt/Quart      (this also has a video at the bottom)
https://github.com/fogleman/Quads


But how to go about doing it in Lazarus using TBgrabmp?
« Last Edit: April 06, 2026, 07:38:46 am by Boleeman »

Boleeman

  • Hero Member
  • *****
  • Posts: 1158
Re: Splitting Picture into Quads using Quadtree ?
« Reply #1 on: April 12, 2026, 02:43:50 am »
Here is a Lazarus quadtree program that uses a set of points.

It was made by Corpsman.


Still trying the work out how to do it for loaded coloured png images !

Dzandaa

  • Hero Member
  • *****
  • Posts: 549
  • From C# to Lazarus
Re: Splitting Picture into Quads using Quadtree ?
« Reply #2 on: May 22, 2026, 01:01:49 pm »
Hi Eddie,

Try this program.

A big thank you to my wife (she's a PH d mathematician) who helped me fix the last bug :)

Lower Threshold = Better Resolution

Pan with left button, zoom with the middle button.

Just tested on Windows.


B->
« Last Edit: May 23, 2026, 12:42:37 pm by Dzandaa »
Regards,
Dzandaa

LeP

  • Sr. Member
  • ****
  • Posts: 350
Re: Splitting Picture into Quads using Quadtree ?
« Reply #3 on: May 23, 2026, 11:52:05 am »
@DZandaa,

thanks for the source.
I tried quickly and seems that there some issues about x, y coordinates (may be exchanged) and generate an AV in various point of your source.

Try with an image with Height <> Width.

I have not time now to debug and report the corrections, but I'll do in the next time.
Un Sistema per domarli, un IDE per trovarli, un codice per ghermirli e nel framework incatenarli.
An operating system to tame them, an IDE to find them, a code to catch them and in the framework chain them.

Dzandaa

  • Hero Member
  • *****
  • Posts: 549
  • From C# to Lazarus
Re: Splitting Picture into Quads using Quadtree ?
« Reply #4 on: May 23, 2026, 12:37:46 pm »
Hi
@Lep:

Thank  you for testing my program.

Effectively, I just tested the algorithm on squares Pictures !!!

The x and y of the Double array  are reversed.

I corrected that.

B->



Regards,
Dzandaa

Dzandaa

  • Hero Member
  • *****
  • Posts: 549
  • From C# to Lazarus
Re: Splitting Picture into Quads using Quadtree New version
« Reply #5 on: May 25, 2026, 12:38:16 pm »
Hi,
Here is a new version showing rectangles boundaries

Have a nice day.

B->

Regards,
Dzandaa

ADMGNS

  • Jr. Member
  • **
  • Posts: 64
  • keep it simple and smart
Re: Splitting Picture into Quads using Quadtree ?
« Reply #6 on: June 06, 2026, 10:44:04 pm »
hello

several years ago, i'd studied on quadtree algorithm which was on video codecs, but it was in D7.

pls see attachment

regs

Dzandaa

  • Hero Member
  • *****
  • Posts: 549
  • From C# to Lazarus
Re: Splitting Picture into Quads using Quadtree ?
« Reply #7 on: June 07, 2026, 12:30:42 pm »
Hi,
@ADMGNS :

Sorry, I don't use Delphi, just Pascal Lazarus.

And the conversion doesn't work well.


B->
Regards,
Dzandaa

ADMGNS

  • Jr. Member
  • **
  • Posts: 64
  • keep it simple and smart
Re: Splitting Picture into Quads using Quadtree ?
« Reply #8 on: June 07, 2026, 01:16:55 pm »
hello again

lazarus conversion plus some minor changes manually, it works minimally now. here is it..

regs

Dzandaa

  • Hero Member
  • *****
  • Posts: 549
  • From C# to Lazarus
Re: Splitting Picture into Quads using Quadtree ?
« Reply #9 on: June 07, 2026, 06:16:22 pm »
Hi,

@ADMGNS:

It works now, but if I load an image and click cmdColorCount, I have a crash here:

Code: Pascal  [Select][+][-]
  1.   for k:=0 to nSize1-1 do
  2.   begin
  3.     c := (p^ shl 8) shr 8; // ie, c := c and $00FFFFFF; // <---- here
  4.     inc(hist[c]);
  5.  
  6.     inc(p);
  7.   end;
  8.  
  9.  

Perhaps the size of the picture is too big.

Also, you can test with

Code: Pascal  [Select][+][-]
  1.  for k:=0 to Pred(nSize1) do
  2.  

I don't know if it is faster.
B->
Regards,
Dzandaa

 

TinyPortal © 2005-2018