Logo by mrob - Contribute your own Logo!

END OF AN ERA, FRACTALFORUMS.COM IS CONTINUED ON FRACTALFORUMS.ORG

it was a great time but no longer maintainable by c.Kleinhuis contact him for any data retrieval,
thanks and see you perhaps in 10 years again

this forum will stay online for reference
News: Visit the official fractalforums.com Youtube Channel
 
*
Welcome, Guest. Please login or register. March 28, 2024, 03:39:02 PM


Login with username, password and session length


The All New FractalForums is now in Public Beta Testing! Visit FractalForums.org and check it out!


Pages: [1]   Go Down
  Print  
Share this topic on DiggShare this topic on FacebookShare this topic on GoogleShare this topic on RedditShare this topic on StumbleUponShare this topic on Twitter
Author Topic: Histogram/Sort equalization  (Read 723 times)
0 Members and 1 Guest are viewing this topic.
SeryZone
Strange Attractor
***
Posts: 253


Contemplate...


« on: May 02, 2014, 10:53:51 AM »

Hello! About 2 months can't implement histogram coloring, like this: http://www.hpdz.net/TechInfo/Colorizing.htm#Histogram

I write programms on delphi. What's I doing wrong???

Code:
Histogram := nil;
        SetLength(Histogram, (max-min));
        NUM:=0;
          for x:=0 to (maxy*maxx-1) do                             //All data points
            if (IterDat[x]<max) then                                   //If less than max
              inc(Histogram[Iterdat[x]-min], IterDat[x]);         //Histogram+=IterationData[x]
...
             ColorIndex := sqrt( Iterdat[x,y] / Histogram[IterDat[x,y]-min]  );   //ColorIndex - between [0;1]
...
      end;

Help me, please!!!
Logged

phtolo
Navigator
*****
Posts: 79



« Reply #1 on: May 02, 2014, 02:42:11 PM »

This is just a wild guess as you may have omitted the missing code.
Are you making the histogram distribution cumulative as mentioned in the linked description ?
Logged
SeryZone
Strange Attractor
***
Posts: 253


Contemplate...


« Reply #2 on: May 02, 2014, 02:45:00 PM »

This is just a wild guess as you may have omitted the missing code.
Are you making the histogram distribution cumulative as mentioned in the linked description ?

Code:
begin
        index := 0;
        Histogram := nil; Percentage:=nil;
        SetLength(Histogram, (max-min-1));
        SetLength(Percentage, (max-min-1));
        NUM:=0;
        for x:=0 to (maxx*maxy-1) do
          if (IterDat[x]<max) then
            inc(Histogram[IterDat[x]-min]);
        for x:=0 to max-min-1 do
          NUM:=NUM+Histogram[x];
        running_total:=0;
        for x:=0 to max-min-1 do
          begin
            running_total := running_total + histogram[x];
            percentage[x] := running_total / NUM;
          end;
          for y := 0 to maxy-1 do
            for x := 0 to maxx-1 do
          begin
            if (IterDat[x*maxy+y] >= max) then
            begin
              buffer[index] := 0; // red
              buffer[index + 1] := 0; // green
              buffer[index + 2] := 0; // blue
            end
            else if (IterDat[x*maxy+y] > 0) and (IterDat[x*Maxy+y]<max) then
              ColorIndex := round( 4096*(percentage[IterDat[x*maxy+y]-min]) ) mod 4096;
            begin
              buffer[index] := pal[ColorIndex].b; // red
              buffer[index + 1] := pal[ColorIndex].g; // green
              buffer[index + 2] := pal[ColorIndex].r; // blue
            end;
            inc(index, 4)
          end;
      end;
  end;

Here, I implemented it! But it too rough... How to make Rank-order???
Logged

phtolo
Navigator
*****
Posts: 79



« Reply #3 on: May 03, 2014, 08:11:37 AM »

Glad it worked!

Btw, I think you have misplaced a begin in the code above.

Code:
            else if (IterDat[x*maxy+y] > 0) and (IterDat[x*Maxy+y]<max) then
              ColorIndex := round( 4096*(percentage[IterDat[x*maxy+y]-min]) ) mod 4096;
            begin
              buffer[index] := pal[ColorIndex].b; // red
              buffer[index + 1] := pal[ColorIndex].g; // green
              buffer[index + 2] := pal[ColorIndex].r; // blue
            end;

should read

Code:
            else if (IterDat[x*maxy+y] > 0) and (IterDat[x*Maxy+y]<max) then
            begin   //<-- moved up one row
              ColorIndex := round( 4096*(percentage[IterDat[x*maxy+y]-min]) ) mod 4096;
              buffer[index] := pal[ColorIndex].b; // red
              buffer[index + 1] := pal[ColorIndex].g; // green
              buffer[index + 2] := pal[ColorIndex].r; // blue
            end;

Only by looking at it, rank-ordered seems to make quite similar results.
Create an array with values from 0 to maxx*maxy-1 and sort IterDat while making the same changes to the new array.
The new array is used to keep track of the original index. Color according to the new index after sorting.
You probably need to implement your own sorting algorithm for this.
Logged
SeryZone
Strange Attractor
***
Posts: 253


Contemplate...


« Reply #4 on: May 03, 2014, 05:16:10 PM »

Glad it worked!

Btw, I think you have misplaced a begin in the code above.

Code:
            else if (IterDat[x*maxy+y] > 0) and (IterDat[x*Maxy+y]<max) then
              ColorIndex := round( 4096*(percentage[IterDat[x*maxy+y]-min]) ) mod 4096;
            begin
              buffer[index] := pal[ColorIndex].b; // red
              buffer[index + 1] := pal[ColorIndex].g; // green
              buffer[index + 2] := pal[ColorIndex].r; // blue
            end;

should read

Code:
            else if (IterDat[x*maxy+y] > 0) and (IterDat[x*Maxy+y]<max) then
            begin   //<-- moved up one row
              ColorIndex := round( 4096*(percentage[IterDat[x*maxy+y]-min]) ) mod 4096;
              buffer[index] := pal[ColorIndex].b; // red
              buffer[index + 1] := pal[ColorIndex].g; // green
              buffer[index + 2] := pal[ColorIndex].r; // blue
            end;

Only by looking at it, rank-ordered seems to make quite similar results.
Create an array with values from 0 to maxx*maxy-1 and sort IterDat while making the same changes to the new array.
The new array is used to keep track of the original index. Color according to the new index after sorting.
You probably need to implement your own sorting algorithm for this.

Thanks, my mistake))) One bug fixed)
But 2560x1440 or even 1920x1080 elements make stack overflow!!!

Code:
procedure QuickSort(first,last:integer;var m:array of integer);
var i,j,n:integer;
    c, x:integer;
begin
  i:=first;
  j:=last;
  x:=m[(first+last) div 2]; {выбираем серединный элемент массива и делим массив пополам}
  repeat
    while m[i]>x do i:=i+1; {считываем всю левую часть до этого элемента}
    while x>m[j] do j:=j-1; {считываем всю правую часть до этого элемента}
    if i<=j then
     begin
       c:=m[i]; {Сортируем элементы массива}
       m[i]:=m[j];
       m[j]:=c;
       i:=i+1;
       j:=i-1;
     end;
   until i>j;
   if first<j then QuickSort(first,j,m);
   if i<last then QuickSort(i,last,m);
  end;

Stack over...FLOWWWWW!!! I laugh about myself's stupidness...
Logged

phtolo
Navigator
*****
Posts: 79



« Reply #5 on: May 04, 2014, 09:54:24 AM »

You probably need to find a sorting algorithm that isn't recursive.

Or increase the stack size (not sure how to do this in delphi).
Logged
SeryZone
Strange Attractor
***
Posts: 253


Contemplate...


« Reply #6 on: May 04, 2014, 02:21:18 PM »

You probably need to find a sorting algorithm that isn't recursive.

Or increase the stack size (not sure how to do this in delphi).


I didn't find it. What Can I Do?
Logged

phtolo
Navigator
*****
Posts: 79



« Reply #7 on: May 04, 2014, 02:57:40 PM »

Try this one:
http://delphi.wikia.com/wiki/Bubble_sort
Logged
knighty
Fractal Iambus
***
Posts: 819


« Reply #8 on: May 04, 2014, 08:15:55 PM »

In your quicksort procedure you did:
j:=i-1; {Shouldn't it be: j:=j-1; ?}

Anyway, There are a lot of examples for quicksort functions for Delphi out there. googling for "delphi quicksort example" and selecting the first match gives: http://delphi.about.com/od/objectpascalide/a/quicksort.htm

Good luck. smiley
Logged
SeryZone
Strange Attractor
***
Posts: 253


Contemplate...


« Reply #9 on: May 05, 2014, 03:57:19 PM »

Thanks, sorting very fast.

So, how to make Rank-Ordered??? Sorting IterDat don't gives any changes!!!

Code:
begin
        index := 0;
        Histogram := nil; Percentage:=nil; DX:=nil;
        SetLength(Histogram, (max-min));
        SetLength(Percentage, (max-min));
        NUM:=0;
        Setlength(dx, maxx*maxy);
        for x:=0 to (maxx*maxy-1) do
          dx[x]:=IterDat[x];
        QuickSort(dx, low(dx), High(dx));   //<---------------------------
        for x:=0 to (maxx*maxy-1) do
          if dx[x]<max then
          inc(Histogram[dx[x]-min]);
        for x:=1 to max-min do
          NUM:=NUM+Histogram[x];
        running_total:=0;
        for x:=1 to max-min do
          begin
            running_total := running_total + histogram[x];
            percentage[x] := running_total / NUM;
          end;
          for y := 0 to maxy-1 do
            for x := 0 to maxx-1 do
          begin
            if (IterDat[x*maxy+y] >= max) then
            begin
              buffer[index] := 0; // red
              buffer[index + 1] := 0; // green
              buffer[index + 2] := 0; // blue
            end
            else if (IterDat[x*maxy+y] >= 0) and (IterDat[x*Maxy+y]<max) then
            begin
              ColorIndex := round( 4095*(percentage[IterDat[x*maxy+y]-min]) );
              buffer[index] := pal[ColorIndex].b; // red
              buffer[index + 1] := pal[ColorIndex].g; // green
              buffer[index + 2] := pal[ColorIndex].r; // blue
            end;
            inc(index, 4)
          end;
      end;
Logged

SeryZone
Strange Attractor
***
Posts: 253


Contemplate...


« Reply #10 on: May 05, 2014, 05:12:06 PM »

I did it!!! Smooth coloring + Rank-Ordered!!! Whhhhhhhhhooooooooooooooooooooooohhhhhhhhhhhhoooooooooooooooooooooooooooooooo!!!!!!!!!! I love all people!!!!! Who read: be happy!!! the wave
 Cantor Dance Smiling Mandelbrot


Code:
begin
        index := 0;
        Histogram := nil; Percentage:=nil;
        SetLength(Histogram, (max-min));
        SetLength(Percentage, (max-min));
        NUM:=0;
        {for x:=0 to (maxx*maxy-1) do
          if IterDat[x]<max then
            histogram[IterDat[x]-min]:=1;}
        for x:=0 to (maxx*maxy-1) do
          if IterDat[x]<max then
            inc(Histogram[IterDat[x]-min]);
        for x:=1 to max-min do
          Histogram[x]:=round(sqrt(Histogram[x]));
        for x:=1 to max-min do
          NUM:=NUM+Histogram[x];
        running_total:=0;
        for x:=1 to max-min do
          begin
            running_total := running_total + histogram[x];
            percentage[x] := running_total / NUM;
          end;
          for y := 0 to maxy-1 do
            for x := 0 to maxx-1 do
          begin
            if (IterDat[x*maxy+y] >= max) then
            begin
              buffer[index] := 0; // red
              buffer[index + 1] := 0; // green
              buffer[index + 2] := 0; // blue
            end
            else if (IterDat[x*maxy+y] >= 0) and (IterDat[x*Maxy+y]<max) then
            begin
              ColorIndex := round( 4095*(percentage[IterDat[x*maxy+y]-min]-((percentage[IterDat[x*maxy+y]-min]-percentage[IterDat[x*maxy+y]-min-1])*SmD[x*maxy+y])) );
              buffer[index] := pal[ColorIndex].b; // red
              buffer[index + 1] := pal[ColorIndex].g; // green
              buffer[index + 2] := pal[ColorIndex].r; // blue
            end;
            inc(index, 4)
          end;
      end;

I use sqrt() for equalization

Histogram:

Sqrt:
« Last Edit: May 05, 2014, 05:25:24 PM by SeryZone » Logged

phtolo
Navigator
*****
Posts: 79



« Reply #11 on: May 05, 2014, 05:22:04 PM »

1. Create an array with values from 0 to maxx*maxy-1
Code:
       Setlength(dx, maxx*maxy);
        for x:=0 to (maxx*maxy-1) do
          dx[x]:=x;

2. and sort IterDat while making the same changes to the new array
Code:
procedure QuickSort(first,last:integer;var m,m2:array of integer);
...
       c:=m[i];
       m[i]:=m[j];
       m[j]:=c;
       c:=m2[i];
       m2[i]:=m2[j];
       m2[j]:=c;
...
   if first<j then QuickSort(first,j,m,m2);
   if i<last then QuickSort(i,last,m,m2);
...

3. Color according to the new index after sorting
Code:
        QuickSort(low(IterDat), High(IterDat), IterDat, dx);
          for y := 0 to maxy-1 do
            for x := 0 to maxx-1 do
          begin
index := 4 * dx[x*maxy+y];
            if (IterDat[x*maxy+y] >= max) then
            begin
              buffer[index] := 0; // red
              buffer[index + 1] := 0; // green
              buffer[index + 2] := 0; // blue
            end
            else if (IterDat[x*maxy+y] >= 0) and (IterDat[x*Maxy+y]<max) then
            begin
              ColorIndex := round( 4095*((x*maxy+y) / (maxx*maxy)) );
              buffer[index] := pal[ColorIndex].b; // red
              buffer[index + 1] := pal[ColorIndex].g; // green
              buffer[index + 2] := pal[ColorIndex].r; // blue
            end;
end;
Logged
phtolo
Navigator
*****
Posts: 79



« Reply #12 on: May 05, 2014, 05:22:54 PM »

Doh, too slow..

Glad you solved it!!!
Logged
SeryZone
Strange Attractor
***
Posts: 253


Contemplate...


« Reply #13 on: May 05, 2014, 07:02:31 PM »

Doh, too slow..

Wait for 2 hours and gave up...
Logged

Pages: [1]   Go Down
  Print  
 
Jump to:  

Related Topics
Subject Started by Replies Views Last post
Histogram jitter test 1 FractalWorks Gallery Duncan C 0 1815 Last post December 20, 2008, 03:57:59 AM
by Duncan C
Histogram jitter test 2 FractalWorks Gallery Duncan C 0 1503 Last post December 20, 2008, 03:58:00 AM
by Duncan C
Histogram Coloring Issue Programming clonexpert 9 3813 Last post February 21, 2010, 04:29:28 AM
by Duncan C
Histogram equalization tests Images Showcase (Rate My Fractal) SeryZone 0 848 Last post May 02, 2014, 07:58:02 PM
by SeryZone
histogram colouring is really streching (not true histogram) Kalles Fraktaler claude 3 10715 Last post December 14, 2014, 11:34:00 PM
by claude

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines

Valid XHTML 1.0! Valid CSS! Dilber MC Theme by HarzeM
Page created in 0.254 seconds with 24 queries. (Pretty URLs adds 0.019s, 2q)