Switch to full style
Post all Gimp scripts and script writing questions here
Post a reply

Re: Gluas

Mon May 30, 2011 10:41 pm

Maybe for Ubuntu, well worth a try version 0.1.19 ?
http://pippin.gimp.org/plug-ins/gluas/files/

Re: Gluas

Mon May 30, 2011 10:47 pm

I have those. I noticed the Japanese site had a couple that gimp-gluas doesn't have.

Re: Gluas

Tue May 31, 2011 4:03 am

Night Vision :)

Image

Re: Gluas

Tue May 31, 2011 4:09 am

Here is the Kuwahara filter with curves after ward set to a cone line.
Pretty cool grunge effect Lyle. :)

Image

Re: Gluas

Tue May 31, 2011 5:57 am

Fix the dogwaflle scripts should not be hard , replace the "dog" calls with a equivalent "gimp" call should fix, but i wonder if is worth the effort

may be more interesting port script as Kuwahara to gmic or mathmap (the language seems a bit more similar to MM ) that for sure may support it.

just in case somebody interested here the code


Kuwahara filter
Code:
-- origine : http://pippin.gimp.org/image_processing/chap_area.html#example_kuwahara


-- Kuwahara filter
--
--
-- Performs the Kuwahara Filter. This filter is an edge-preserving filter.
--
--
-- ( a  a  ab   b  b)
-- ( a  a  ab   b  b)
-- (ac ac abcd bd bd)
-- ( c  c  cd   d  d)
-- ( c  c  cd   d  d)
--
-- In each of the four regions (a, b, c, d), the mean brightness and the variance are calculated. The
-- output value of the center pixel (abcd) in the window is the mean value of that region that has the
-- smallest variance.
--
-- description copied from http://www.incx.nec.co.jp/imap-vision/library/wouter/kuwahara.html
--
-- implemented by Øyvind Kolås <oeyvindk@hig.no> 2004


-- the sampling window is:  width=size*2+1  height=size*2+1

size = 4

edge_duplicate = 1;

-- local function to get the mean value, and
-- variance from the rectangular area specified
function mean_and_variance (x0,y0,x1,y1)
local variance
local mean

local min         = 1.0
local max         = 0.0
local accumulated = 0
local count       = 0
   
local x, y

for y=y0,y1 do
   for x=x0,x1 do
     local v = get_value(x,y)

     accumulated   = accumulated + v
     count         = count + 1
     
     if v<min then min = v end
     if v>max then max = v end

    end
  end

  variance = max-min
  mean     = accumulated /count
   
  return mean, variance
end

-- local function to get the mean value, and
-- variance from the rectangular area specified
function rgb_mean_and_variance (x0,y0,x1,y1)
local variance
local mean
local r_mean
local g_mean
local b_mean

local min           = 1.0
local max           = 0.0
local accumulated_r = 0
local accumulated_g = 0
local accumulated_b = 0
local count         = 0
   
local x, y

for y=y0,y1 do
   for x=x0,x1 do
     local v     = get_value(x,y)
     local r,g,b = get_rgb (x,y)

     accumulated_r   = accumulated_r + r
     accumulated_g   = accumulated_g + g
     accumulated_b   = accumulated_b + b
     count         = count + 1
     
     if v<min then min = v end
     if v>max then max = v end

    end
  end

  variance = max-min
  mean_r   = accumulated_r /count
  mean_g   = accumulated_g /count
  mean_b   = accumulated_b /count
   
  return mean_r, mean_g, mean_b, variance
end

-- return the kuwahara computed value
function kuwahara(x, y, size)
  local best_mean     = 1.0
  local best_variance = 1.0

  local mean, variance
   
  mean, variance = mean_and_variance (x-size, y-size, x, y)   

  if variance < best_variance then
    best_mean     = mean
    best_variance = variance
  end
   
  mean, variance = mean_and_variance (x, y-size, x+size,y)

  if variance < best_variance then
    best_mean     = mean
    best_variance = variance
  end   
   
  mean, variance = mean_and_variance (x, y, x+size, y+size)

  if variance < best_variance then
    best_mean     = mean
    best_variance = variance
  end   
   
  mean, variance = mean_and_variance (x-size, y, x,y+size)

  if variance < best_variance then
    best_mean     = mean
    best_variance = variance
  end   

  return best_mean
end


-- return the kuwahara computed value
function rgb_kuwahara(x, y, size)
  local best_r, best_g, best_b
  local best_variance = 1.0

  local r,g,b, variance
   
  r,g,b, variance = rgb_mean_and_variance (x-size, y-size, x, y)   

  if variance < best_variance then
    best_r, best_g, best_b = r, g, b
   
    best_variance = variance
  end
   
  r,g,b, variance = rgb_mean_and_variance (x, y-size, x+size,y)

  if variance < best_variance then
    best_r, best_g, best_b = r, g, b
    best_variance = variance
  end   
   
  r,g,b, variance = rgb_mean_and_variance (x, y, x+size, y+size)

  if variance < best_variance then
    best_r, best_g, best_b = r, g, b
    best_variance = variance
  end   
   
  r,g,b, variance = rgb_mean_and_variance (x-size, y, x,y+size)

  if variance < best_variance then
    best_r, best_g, best_b = r, g, b
    best_variance = variance
  end   

  return best_r, best_g, best_b
end

function kuwahara(radius)
  for y=0, height-1 do
    for x=0, width-1 do
      r,g,b = rgb_kuwahara (x,y, radius)
      set_rgb (x,y, r,g,b)
    end
    progress (y/height)
  end
end

kuwahara(2)

Re: Gluas

Tue May 31, 2011 6:05 am

Is there any code visible for the Kuwahara effect ? I think this could be done in G'MIC ;)

Re: Gluas

Tue May 31, 2011 6:06 am

It's hiding behind PC's spoiler

Re: Gluas

Tue May 31, 2011 6:08 am

David maybe the original C script (well look as C to me , but i may be wrong) is easier to port.
The Lua filter was derieved by this


here #include <stddef.h>
#include <imapio.h>
#include <stdimap.h>

/*-----------------------------------------------------------------
Kuwahara Filter

12/01/99
filename: kuwahara.lc
author : W.J.Bokhove
----------------------------------------------------------------*/

/*
M_DOCDEF kuwahara

NAME kuwahara

SYNOPSIS
void kuwahara(src, dst, lines)
sep uchar src[]; /* source image */ /*
sep uchar dst[]; /* destination image */ /*
uint lines; /* number of lines to work on */ /*

MEMORY CONSUMPTION
This function consumes about 22 lines of IMAP memory

DESCRIPTION
Performs the Kuwahara Filter. This filter is an edge-preserving filter.
( a a ab b b)
( a a ab b b)
(ac ac abcd bd bd)
( c c cd d d)
( c c cd d d)
In each of the four regions (a, b, c, d), the mean brightness and the
variance are calculated. The output value of the center pixel (abcd) in
the window is the mean value of that region that has the smallest variance.

M_DOCEND
*/


void kuwahara(sep uchar src[], sep uchar dst[], uint lines)
{
#define square(a) (a*a)
int i;
sep ulong dif;
sep uint dtmp1, dtmp2, dtmp3, dtmp4, acc;
sep uchar var[3], mean[3], vartmp, meantmp;

dst[0] = 0;
dst[1] = 0;
/* Calculate Variance and Mean of first 2 lines */
dtmp2 = square((src[0] - :>src[1]));
dtmp3 = square((src[0] - src[1]));
dtmp4 = square((src[0] - :<src[1]));
dif = :<dtmp2 + dtmp3 + :>dtmp4;
dtmp1 = square((src[1] - :>src[1]));
dif += dtmp1;
dif += :<dtmp1;
dtmp2 = square((src[1] - :>src[2]));
dif += dtmp2;
dtmp3 = square((src[1] - src[2]));
dif += dtmp3;
dtmp4 = square((src[1] - :<src[2]));
dif += dtmp4;
var[1] = dif;
dif = :<dtmp2 + dtmp3 + :>dtmp4;
dtmp1 = square((src[2] - :>src[2]));
dif += dtmp1;
dif += :<dtmp1;
dtmp2 = square((src[2] - :>src[3]));
dif += dtmp2;
dtmp3 = square((src[2] - src[3]));
dif += dtmp3;
dtmp4 = square((src[2] - :<src[3]));
dif += dtmp4;
var[2] = dif;
acc = src[0] + src[1] + src[2];
acc += (:<acc + :>acc);
mean[1] = acc / 9;
acc = src[2] + src[2] + src[3];
acc += (:<acc + :>acc);
mean[2] = acc / 9;

for (i=3 ; i<lines-1; i++ ) {
/* Calculate Variance */
dif = :<dtmp2 + dtmp3 + :>dtmp4;
dtmp1 = square((src[i] - :>src[i]));
dif += dtmp1;
dif += :<dtmp1;
dtmp2 = square((src[i] - :>src[i+1]));
dif += dtmp2;
dtmp3 = square((src[i] - src[i+1]));
dif += dtmp3;
dtmp4 = square((src[i] - :<src[i+1]));
dif += dtmp4;
var[3]= sqrtsepi(dif>>3);
/* Calculate Mean */
acc = src[i-1] + src[i] + src[i+1];
acc += (:<acc + :>acc);
mean[3] = acc / 9;
/* Find minimum variance and its mean */
vartmp = :>var[1];
meantmp = :>mean[1];
mif (:<var[1] < vartmp) {meantmp = :<mean[1]; vartmp = :<var[1];}
mif (:>var[3] < vartmp) {meantmp = :>mean[3]; vartmp = :>var[3];}
mif (:<var[3] < vartmp) meantmp = :<mean[3];
dst[i-1] = meantmp;
var[1] = var[2]; mean[1] = mean[2];
var[2] = var[3]; mean[2] = mean[3];
}
dst[lines-2] = 0;
dst[lines-1] = 0;

From http://web.archive.org/web/200803130937 ... uwahara.lc

Re: Gluas

Tue May 31, 2011 8:27 am

Ok, Thanks for the pointers. I've recoded it from scratch in G'MIC, it is quite short to perform in this beautiful language :)

#@gmic kuwahara : size>0
#@gmic : Apply Kuwahara filter of specified size on selected images.
#@gmic : $ image.jpg --kuwahara 5
kuwahara : -check $1>0
-e[^-1] "Apply Kuwahara filter of size $1 on image$?."
-v - -to_rgb -repeat @#
--dilate[0] $1 --erode[0] $1 -compose_channels[-1] min -compose_channels[-2] max --[-2,-1]
$1,1,1,1,{1/$1} -convolve[0] [-1] -transpose[-1] -convolve[0] [-1] -rm[-1]
-a[-2,-1] c
-f "v1=i(x-1,y-1,0,3,1); \
v2=i(x+1,y+1,0,3,1); \
v3=i(x-1,y+1,0,3,1); \
v4=i(x+1,y+1,0,3,1); \
vm=min(v1,v2,v3,v4); \
if(c>=3,i, \
if(vm==v1,i(x-1,y-1,0,c,1),
if(vm==v2,i(x+1,y-1,0,c,1),
if(vm==v3,i(x-1,y+1,0,c,1),
i(x+1,y+1,0,c,1)))))"
-channels[-1] 0,2
-mv[-1] 0 -done -v +

#@gimp Kuwahara filtering : gimp_kuwahara, gimp_kuwahara_preview(0)
#@gimp : Radius = int(3,1,30)
#@gimp : Channel(s) = choice("All","RGBA","RGB","Luminance","Blue/red chrominances","Blue chrominance","Red chrominance","Lightness","ab-components","a-component","b-component","Hue","Saturation","Value","Key","Alpha","ch-components","c-component","h-component")
#@gimp : sep = separator(), Preview type = choice("Full","Forward horizontal","Forward vertical","Backward horizontal","Backward vertical")
#@gimp : sep = separator(), note = note("<small>Author : <i>David Tschumperl&#233;</i>. Latest update : <i>2011/05/31</i>.</small>")
gimp_kuwahara :
-apply_channels "-kuwahara $1",$2,0

gimp_kuwahara_preview :
-gimp_split_preview "-gimp_kuwahara ${1--2}",$-1


I got this :

Image

Should be already available after filter update.

Re: Gluas

Tue May 31, 2011 8:39 am

thank David

I am wrong or the original filter was basically equivalent to a Convolution Matrix preset ?
Something as the many presets (erode ,dilate,highpass,etc) that may be created by
http://docs.gimp.org/2.6/en/plug-in-convmatrix.html ?

Re: Gluas

Tue May 31, 2011 8:41 am

I agree; I think all the Gluas presets can be done (and better) in G'MIC if you know how to code. Gluas is quite old; want to say I vaguely remembered it in the old GIMP 1.2.x days. G'MIC is new and it's like comparing a corvette with a volkswagon beetle. lol

And PC Ninja'ed me. lol

:)

Re: Gluas

Tue May 31, 2011 8:47 am

@PhotoComiX : not it is quite different than applying a convolution filter. In fact, this is quite a strange process, I really doubt it can be useful for image denoising for instance. but who knows...

Re: Gluas

Tue May 31, 2011 8:54 am

Hey David. Not sure what Kuwahara in Glaus is actually doing. It's almost like a combination of noise spread followed by and adaptive erosion or dilation depending on the value of the bits. Just not sure. Just tried out your new preset and it's not quite the same but cool none the less. What I find really cool with Kuwahara is to do the following. Dup, run the Glaus Kuwahara and then set that result to Grain Extract and copy visible. Delete the Glaus Kuwahar layer and then set the result layer to Grain Merge. Makes for a hyper sharpening effect. :)

Re: Gluas

Tue May 31, 2011 9:56 am

Just found out that 0.1.20 doesn't run Decimation preset; bummer. Went back to 0.1.19 and all's well. Not sure what changes in 0.1.20 caused this preset to not work. Oh well. Like Decimation, so guess I'm sticking with 0.1.19 for now. :)

Re: Gluas

Tue May 31, 2011 10:49 am

Yeah Glaus 01.19 seems to run most of them.
I agree GMIC could handle these way better and probably with cleaner code.
Thanks David for the new filter by the way. :)

Re: Gluas

Tue May 31, 2011 11:26 am

I've just done a small correction, there was a bug in my code, sorry.
Now, this looks a little better.

Re: Gluas

Tue May 31, 2011 11:31 am

Where is it? Is it something I need to put into my .gmic file?

Re: Gluas

Tue May 31, 2011 11:33 am

No, basically you should only click the 'Update filters' button, while the 'Internet' button is set.
You need also G'MIC >= 1.4.9.2.
The filter is located in folder 'Enhancement/Kuwahara filtering'.

Re: Gluas

Tue May 31, 2011 11:36 am

Thanks! Found it.

Re: Gluas

Tue May 31, 2011 11:40 am

Looks great David! :)
Image
Post a reply