Jump to content

Fill with Mode of Colors


Recommended Posts

How this code works is to create a 3D box, and to grab the mode from the created 3D box. It only should run once. I do admit that code needs to be improved on though.


It's made to solve this thread (though too late to post there) -


-1 implies that if there is more than 1 mode, then the canvas will not be filled with colors. Otherwise, you can choose which mode to fill on the canvas.



// Name:
// Submenu:
// Author:
// Title:
// Version:
// Desc:
// Keywords:
// URL:
// Help:
#region UICode
IntSliderControl color_position = -1; // [-1,100] Color Position

int[,,] col3d = null;
bool proceed=true;
List<int> r_cols = new List<int>();
List<int> g_cols = new List<int>();
List<int> b_cols = new List<int>();
List<int> r_cols_mf = new List<int>();
List<int> g_cols_mf = new List<int>();
List<int> b_cols_mf = new List<int>();
List<int> counts = new List<int>();
int maxfreqcounts=0;

void PreRender(Surface dst, Surface src)
    if (proceed){
     int size_of_count = 0;
     int maxval=0;

     Rectangle selection = EnvironmentParameters.SelectionBounds;
     col3d = new int[256,256,256];
     for (int y = selection.Top; y < selection.Bottom; y++)
         for (int x = selection.Left; x < selection.Right; x++)
            ColorBgra img_pixels = src[x,y];

     for (int xcol3d = 0 ; xcol3d < 256 ; xcol3d++)
        for (int ycol3d = 0 ; ycol3d < 256 ; ycol3d++)
            for (int zcol3d = 0 ; zcol3d < 256 ; zcol3d++)

     for (int nmv = 0 ; nmv <size_of_count ; nmv++){

     for (int nmf = 0 ; nmf <size_of_count ; nmf++){

void Render(Surface dst, Surface src, Rectangle rect)
    // Delete any of these lines you don't need;

    ColorBgra currentPixel;
    for (int y = rect.Top; y < rect.Bottom; y++)
        if (IsCancelRequested) return;
        for (int x = rect.Left; x < rect.Right; x++)
            currentPixel = src[x,y];
            if (color_position==-1)
                if(maxfreqcounts>1) {dst[x,y]=src[x,y];}
                else {dst[x,y] = ColorBgra.FromBgraClamped(b_cols_mf[0], g_cols_mf[0], r_cols_mf[0], 255);}
            else {dst[x,y] = ColorBgra.FromBgraClamped(b_cols_mf[color_position%maxfreqcounts], g_cols_mf[color_position%maxfreqcounts], r_cols_mf[color_position%maxfreqcounts], 255);}



Edited by Reptillian

G'MIC Filter Developer

Link to comment
Share on other sites

2 hours ago, midora said:

@Reptillian Could you please add a source picture and the result? Just to get a better idea what you like to achieve.

I guess I have a rough idea what you like to do but the result is not what I expect.









All it does is to take the color with the most common appearance. It does that by accumulating 3D box info, and extracting info from a 3D box. As mentioned, -1 only takes in 1 mode, otherwise you would have to choose the color when it's not -1. If no changes appear on -1, that means there are more than 1 mode or no mode exists.

Edited by Reptillian

G'MIC Filter Developer

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...