Topic: About upgrade of fractal interpolation plugin

This plugin works much better than Oneone software Perfect Resize 7. I tried a much software for image enlargement, and i know now, what your thing best. But I suggest to you modern this stuff. A few days ago i tried example-based image super resolution techology. The result was a sharp magnified image, but in which was a lot of artifacts. Maybe there's a chance to train as a fractal interpolation, as bicubic?

2

Re: About upgrade of fractal interpolation plugin

I don't know anything about example-based image super resolution. Could you provide some references? Which software did you try?

Michael Vinther

> software developer <

Re: About upgrade of fractal interpolation plugin

Of course, i have a matlab code and reference in PDF. But i must send it to you by e-mail, because it had not seen on this forum features file attachments.

4

Re: About upgrade of fractal interpolation plugin

Thank you, I will have a look at it.

Michael Vinther

> software developer <

Re: About upgrade of fractal interpolation plugin

I find this in russian internet:

include "defines.sci"

const int SCALE = 4;
const float MD = 0.7;

// возвращает средний цвет по указанной области
func vector getSum( int L, int x0, int y0, int x1, int y1 )
  var int i, j;
  var vector v;
{
    v:=[0,0,0];

    for i:=y0 to y1 loop
    for j:=x0 to x1 loop
        v:=v+s_GetPixel( L, j, i );

    return v*(1.0/((x1-x0+1)*(y1-y0+1)));
}

// покомпонентное умножение вектора
func vector mult( vector a, vector b )
     return [a.x*b.x, a.y*b.y, a.z*b.z];


// безопасное деление 
func float div0( float x, float y )
     if abs(y)>abs(x)
     then return x/y;
     else if abs(x) > 1e10*abs(y)
          then if abs(x)<1e-10
               then return 0;
               else 
                    return 1e10;
          else return x/y;

// покомпонентное деление
func vector div( vector a, vector b )
     return [div0(a.x,b.x), div0(a.y,b.y), div0(a.z,b.z)];


const float SG = 0.2;
func float segm( float x )
     if x<SG then return 0;
              else if x>(1-SG) then return 1;
                            else return SG+(x-SG)/(1-SG*2);

// отображение из ранговой области S
// в домен в D.
// в углах домена заданы коэффициенты линейного отображения.
// в промежуточных точках коэффициенты линейно интерполируются
//  0,0      0,1
//  1,0      1,1
func void fill_bar( int S, int D, int scale
                 , int dx0, int dy0, int dx1, int dy1 // destination domain area
                 , var vector add[2,2], var vector mul[2,2]
                 )
  var int i, j;
  var float dx, dy;
  var vector addy0, muly0, addy1, muly1, addx, mulx;
{
    for i:=0 to scale*2-1 loop
    {
        { //-------------- интерполируем коэф. по вертикали -------
        addy0 := add[0,0]+(add[1,0]-add[0,0])*dy;
        addy1 := add[0,1]+(add[1,1]-add[0,1])*dy;

        muly0 := mul[0,0]+(mul[1,0]-mul[0,0])*dy;
        muly1 := mul[0,1]+(mul[1,1]-mul[0,1])*dy;
        } 
            where    dy:= ( float(i)/(scale*2-1) );

        for j:=0 to scale*2-1 loop
        {
            { //-------------- интерполируем коэф. по горизонтали -
            addx:=addy0+(addy1-addy0)*dx;
            mulx:=muly0+(muly1-muly0)*dx;
            }
                where   dx:= ( float(j)/(scale*2-1) );

            s_SetPixel( D, dx0+j, dy0+i
                      , mult( mulx, getSum( S
                                          , dx0-scale+j*2,   dy0-scale+i*2
                                          , dx0-scale+j*2+1, dy0-scale+i*2+1
                                          )
                            ) + addx );
        }
    }
}

// расчёт коэф. системы линейных уравнений
// e0*a + b = c0 
// e1*a + b = c0
func void calc_abp( float e0, float c0, float e1, float c1, var float a, var float b )
{
     if  abs(e0-e1)<1e-4
     then
     { // если от одинакового параметра пытаемся получить 2 разных результата
          a := 0;
          b := c0;
     }
     else
     {
          a := div0( c0-c1, e0-e1 );

          // слишком большой контраст усекаем для сходимости итерации распаковки
          if a>MD 
          then a:=MD;
          else if a<-MD then a:=-MD;

          b := c0 - a * e0;
     }
}

// расчёт коэф. линейного уровнения для всех цветовых плоскостей RGB (xyz)
func void calc_ab( vector e0, vector c0, vector e1, vector c1, var vector a, var vector b )
var float aa, bb;
{
     calc_abp( e0.x, c0.x, e1.x, c1.x, aa, bb ); a.x:=aa; b.x:=bb;
     calc_abp( e0.y, c0.y, e1.y, c1.y, aa, bb ); a.y:=aa; b.y:=bb;
     calc_abp( e0.z, c0.z, e1.z, c1.z, aa, bb ); a.z:=aa; b.z:=bb;
}

// расчёт коэф. линейного уровнения для указанного угла домена
func void calc_abi( var vector e[2,2], var vector c[2,2], var vector a[2,2], var vector b[2,2]
                  , vector es, vector cs
                  , int i, int j, )
     calc_ab( e[i,j],   c[i,j]
            , es, cs
            , a[i,j], b[i,j]  );


// функция масштабирования
func void resize( int S, int scale )
 var int i, j, w, h, D, D2,ws, hs, i2, j2, x0, y0, x1, y1, TMP, pass;
 var vector v, c[2,2], e[2,2], a[2,2], b[2,2], es, cs;
 var int ii, jj;
{
    w:=s_GetLayerWidth (S);
    h:=s_GetLayerHeight(S);

    ws:=w*scale;
    hs:=h*scale;

    D :=s_AddLayer( ws, hs, "scaled" );
    D2:=s_AddLayer( ws, hs, "scaled" );

    // предварительное заполнение. только для сходимости
    for i:=0 to hs-1 loop
    for j:=0 to ws-1 loop
        s_SetPixel( D, j, i, s_GetPixel(S,j/scale,i/scale) );


    for pass:=0 to 4 loop
    {
    for i:=0 to h/2 loop // проход по доменам 2x2
    for j:=0 to w/2 loop
    {
        i2:=i*2;
        j2:=j*2;

        for ii:=0 to 1 loop
        for jj:=0 to 1 loop
        {
            c[ii,jj]:=s_GetPixel( S, j2+jj, i2+ii );
            e[ii,jj]:=getSum    ( S, j2-1+jj*2,   i2-1+ii*2
                                   , j2-1+jj*2+1, i2-1+ii*2+1 );
        }
        es:=[0,0,0];
        cs:=[0,0,0];
        for ii:=0 to 1 loop
        for jj:=0 to 1 loop
        {
            es:=es+e[ii,jj];
            cs:=cs+c[ii,jj];
        }
        es:=es*0.25;
        cs:=cs*0.25;

        for ii:=0 to 1 loop
        for jj:=0 to 1 loop
            // два линейных уравнения:
            // 1. угол e[ii,jj] отображается в угол c[ii,jj]
            // 2. среднее значение ранговой области отображается в среднее
            //    значение домена
            calc_abi( e, c, a, b, es,cs, ii, jj );

        x0:= j2*scale;
        x1:= j2*scale+scale*2-1;
        y0:= i2*scale;
        y1:= i2*scale+scale*2-1;

        fill_bar( D, D2, scale
                , x0, y0, x1, y1
                , b, a
                );
    }
        s_SetCurLayer(D2);
        s_UpdateView();
        TMP:=D; D:=D2; D2:=TMP;
    }
    s_RemoveLayer( D  );

}

func void main()
{
     resize(0,SCALE);
}


---------------
I can translate this, but tomorrow.

6

Re: About upgrade of fractal interpolation plugin

What is it? It appers fairly simple, and without being able to read the comments it is a bit hard to guess the meaning..  smile

Michael Vinther

> software developer <

Re: About upgrade of fractal interpolation plugin

It's very simple fractal interpolation code, with many artifacts, when scaling is more than 2x.

include "defines.sci"

const int SCALE = 4;
const float MD = 0.7;

// return average color in selected region
func vector getSum( int L, int x0, int y0, int x1, int y1 )
  var int i, j;
  var vector v;
{
    v:=[0,0,0];

    for i:=y0 to y1 loop
    for j:=x0 to x1 loop
        v:=v+s_GetPixel( L, j, i );

    return v*(1.0/((x1-x0+1)*(y1-y0+1)));
}

// componentwise multiplication of of vector
func vector mult( vector a, vector b )
     return [a.x*b.x, a.y*b.y, a.z*b.z];


// safety division 
func float div0( float x, float y )
     if abs(y)>abs(x)
     then return x/y;
     else if abs(x) > 1e10*abs(y)
          then if abs(x)<1e-10
               then return 0;
               else 
                    return 1e10;
          else return x/y;

// componentwise division
func vector div( vector a, vector b )
     return [div0(a.x,b.x), div0(a.y,b.y), div0(a.z,b.z)];


const float SG = 0.2;
func float segm( float x )
     if x<SG then return 0;
              else if x>(1-SG) then return 1;
                            else return SG+(x-SG)/(1-SG*2);

// display from rank of S
// in the domain of D
// at the corners of domain are given coefficients of a linear map.
// coefficients at intermediate points are linearly interpolated
//  0,0      0,1
//  1,0      1,1
func void fill_bar( int S, int D, int scale
                 , int dx0, int dy0, int dx1, int dy1 // destination domain area
                 , var vector add[2,2], var vector mul[2,2]
                 )
  var int i, j;
  var float dx, dy;
  var vector addy0, muly0, addy1, muly1, addx, mulx;
{
    for i:=0 to scale*2-1 loop
    {
        { //-------------- interpolating coefficient by vertical -------
        addy0 := add[0,0]+(add[1,0]-add[0,0])*dy;
        addy1 := add[0,1]+(add[1,1]-add[0,1])*dy;

        muly0 := mul[0,0]+(mul[1,0]-mul[0,0])*dy;
        muly1 := mul[0,1]+(mul[1,1]-mul[0,1])*dy;
        } 
            where    dy:= ( float(i)/(scale*2-1) );

        for j:=0 to scale*2-1 loop
        {
            { //-------------- interpolating coefficient by horizontal -
            addx:=addy0+(addy1-addy0)*dx;
            mulx:=muly0+(muly1-muly0)*dx;
            }
                where   dx:= ( float(j)/(scale*2-1) );

            s_SetPixel( D, dx0+j, dy0+i
                      , mult( mulx, getSum( S
                                          , dx0-scale+j*2,   dy0-scale+i*2
                                          , dx0-scale+j*2+1, dy0-scale+i*2+1
                                          )
                            ) + addx );
        }
    }
}

// calculation of coefficients of linear equations
// e0*a + b = c0 
// e1*a + b = c0
func void calc_abp( float e0, float c0, float e1, float c1, var float a, var float b )
{
     if  abs(e0-e1)<1e-4
     then
     { // if from same parameter are trying to get two different results
          a := 0;
          b := c0;
     }
     else
     {
          a := div0( c0-c1, e0-e1 );

          // too great a contrast to convergence of iteration truncates the decompression
          if a>MD 
          then a:=MD;
          else if a<-MD then a:=-MD;

          b := c0 - a * e0;
     }
}

// calculation of coefficient of linear equations for all color planes of RGB (xyz)
func void calc_ab( vector e0, vector c0, vector e1, vector c1, var vector a, var vector b )
var float aa, bb;
{
     calc_abp( e0.x, c0.x, e1.x, c1.x, aa, bb ); a.x:=aa; b.x:=bb;
     calc_abp( e0.y, c0.y, e1.y, c1.y, aa, bb ); a.y:=aa; b.y:=bb;
     calc_abp( e0.z, c0.z, e1.z, c1.z, aa, bb ); a.z:=aa; b.z:=bb;
}

// calculation of coefficient of linear equations for a specified angle domain
func void calc_abi( var vector e[2,2], var vector c[2,2], var vector a[2,2], var vector b[2,2]
                  , vector es, vector cs
                  , int i, int j, )
     calc_ab( e[i,j],   c[i,j]
            , es, cs
            , a[i,j], b[i,j]  );


// Scale fuction
func void resize( int S, int scale )
 var int i, j, w, h, D, D2,ws, hs, i2, j2, x0, y0, x1, y1, TMP, pass;
 var vector v, c[2,2], e[2,2], a[2,2], b[2,2], es, cs;
 var int ii, jj;
{
    w:=s_GetLayerWidth (S);
    h:=s_GetLayerHeight(S);

    ws:=w*scale;
    hs:=h*scale;

    D :=s_AddLayer( ws, hs, "scaled" );
    D2:=s_AddLayer( ws, hs, "scaled" );

    // pre-filled. for convergence
    for i:=0 to hs-1 loop
    for j:=0 to ws-1 loop
        s_SetPixel( D, j, i, s_GetPixel(S,j/scale,i/scale) );


    for pass:=0 to 4 loop
    {
    for i:=0 to h/2 loop // pass through the domain 2x2
    for j:=0 to w/2 loop
    {
        i2:=i*2;
        j2:=j*2;

        for ii:=0 to 1 loop
        for jj:=0 to 1 loop
        {
            c[ii,jj]:=s_GetPixel( S, j2+jj, i2+ii );
            e[ii,jj]:=getSum    ( S, j2-1+jj*2,   i2-1+ii*2
                                   , j2-1+jj*2+1, i2-1+ii*2+1 );
        }
        es:=[0,0,0];
        cs:=[0,0,0];
        for ii:=0 to 1 loop
        for jj:=0 to 1 loop
        {
            es:=es+e[ii,jj];
            cs:=cs+c[ii,jj];
        }
        es:=es*0.25;
        cs:=cs*0.25;

        for ii:=0 to 1 loop
        for jj:=0 to 1 loop
            // two linear equations:
            // 1. angle e [ii, jj] is displayed in the angle c [ii, jj]
            // 2. average of rank region displaying to average
            //    domain value
            calc_abi( e, c, a, b, es,cs, ii, jj );

        x0:= j2*scale;
        x1:= j2*scale+scale*2-1;
        y0:= i2*scale;
        y1:= i2*scale+scale*2-1;

        fill_bar( D, D2, scale
                , x0, y0, x1, y1
                , b, a
                );
    }
        s_SetCurLayer(D2);
        s_UpdateView();
        TMP:=D; D:=D2; D2:=TMP;
    }
    s_RemoveLayer( D  );

}

func void main()
{
     resize(0,SCALE);
}

Re: About upgrade of fractal interpolation plugin

It is possible to do this, here site: http://links.uwaterloo.ca/ResearchRecent.html => Fractal image superresolution using a "method of examples"

9

Re: About upgrade of fractal interpolation plugin

I just tried converting the code so that it can be used with Image Analyzer's script plugin. You can also use it if you copy/paste the code to the script dialog.
The results are not very good.. Lots of artifacts and blocking.

using System;
using MeeSoft.Mathematics;
using MeeSoft.ImageProcessing;

public class ScriptOp : MeeSoft.ImageProcessing.Operations.ScriptOperation.Base
{
    const int SCALE = 4;
    const float MD = 0.7f;

    PlanarBitmap[] layers;

    vector s_GetPixel(int L, int x0, int y0)
    {
        return new vector()
        {
            x = layers[L][0].GetPixelSafe(x0,y0),
            y = layers[L][1].GetPixelSafe(x0,y0),
            z = layers[L][2].GetPixelSafe(x0,y0)
        };
    }

    void s_SetPixel(int L, int x0, int y0, vector val)
    {
        if (x0>=layers[L][0].Width || y0>=layers[L][0].Height)
            return;
        layers[L][0][x0,y0] = val.x;
        layers[L][1][x0,y0] = val.y;
        layers[L][2][x0,y0] = val.z;
    }

    struct vector
    {
        public float x, y, z;

        public static vector operator +(vector a, vector b)
        {
            return new vector() { x = a.x+b.x, y = a.y+b.y, z = a.z+b.z};
        }

        public static vector operator -(vector a, vector b)
        {
            return new vector() { x = a.x-b.x, y = a.y-b.y, z = a.z-b.z};
        }

        public static vector operator *(vector a, float b)
        {
            return new vector() { x = a.x*b, y = a.y*b, z = a.z*b};
        }
    }


    // return average color in selected region
    vector getSum( int L, int x0, int y0, int x1, int y1 )
    {
        var v = new vector();

        for (int i=y0; i<=y1; i++)
        for (int j=x0; j<=x1; j++)
            v=v+s_GetPixel( L, j, i );

        return v*(1f/((x1-x0+1)*(y1-y0+1)));
    }

    // componentwise multiplication of of vector
    vector mult( vector a, vector b )
    {
         return new vector() { x = a.x*b.x, y = a.y*b.y, z = a.z*b.z};
    }

    // safety division
    float div0( float x, float y )
    {
         if (Math.Abs(y)>Math.Abs(x))
            return x/y;
         else if (Math.Abs(x) > 1e10*Math.Abs(y))
                  if (Math.Abs(x)<1e-10)
                       return 0;
                  else
                       return 1e10f;
              else return x/y;
    }

    // componentwise division
    vector div( vector a, vector b )
    {
         return new vector() { x=div0(a.x,b.x), y=div0(a.y,b.y), z=div0(a.z,b.z)};
    }

    const float SG = 0.2f;
    float segm( float x )
    {
        if (x<SG)
            return 0;
        else if (x>(1-SG))
            return 1;
        else
            return SG+(x-SG)/(1-SG*2);
    }

    // display from rank of S
    // in the domain of D
    // at the corners of domain are given coefficients of a linear map.
    // coefficients at intermediate points are linearly interpolated
    //  0,0      0,1
    //  1,0      1,1
    void fill_bar( int S, int D, int scale
                     , int dx0, int dy0, int dx1, int dy1 // destination domain area
                     , vector[,] add, vector[,] mul
                     )
    {
        vector addy0, muly0, addy1, muly1, addx, mulx;
        for (int i=0; i<scale*2; i++)
        {
            { //-------------- interpolating coefficient by vertical -------
            var dy= ( i/(scale*2f-1f) );
            addy0 = add[0,0]+(add[1,0]-add[0,0])*dy;
            addy1 = add[0,1]+(add[1,1]-add[0,1])*dy;

            muly0 = mul[0,0]+(mul[1,0]-mul[0,0])*dy;
            muly1 = mul[0,1]+(mul[1,1]-mul[0,1])*dy;
            }
            for (int j=0; j<scale*2; j++)
            {
                { //-------------- interpolating coefficient by horizontal -
                var dx= ( j/(scale*2f-1f) );
                addx=addy0+(addy1-addy0)*dx;
                mulx=muly0+(muly1-muly0)*dx;
                }
                s_SetPixel( D, dx0+j, dy0+i
                          , mult( mulx, getSum( S
                                              , dx0-scale+j*2,   dy0-scale+i*2
                                              , dx0-scale+j*2+1, dy0-scale+i*2+1
                                              )
                                ) + addx );
            }
        }
    }

    // calculation of coefficients of linear equations
    // e0*a + b = c0
    // e1*a + b = c0
    void calc_abp( float e0, float c0, float e1, float c1, out float a, out float b )
    {
         if (Math.Abs(e0-e1)<1e-4)
         { // if from same parameter are trying to get two different results
              a = 0;
              b = c0;
         }
         else
         {
              a = div0( c0-c1, e0-e1 );

              // too great a contrast to convergence of iteration truncates the decompression
              if (a>MD) a=MD;
              else if (a<-MD) a=-MD;

              b = c0 - a * e0;
         }
    }

    // calculation of coefficient of linear equations for all color planes of RGB (xyz)
    void calc_ab( vector e0, vector c0, vector e1, vector c1, out vector a, out vector b )
    {
        float aa, bb;
        calc_abp( e0.x, c0.x, e1.x, c1.x, out aa, out bb ); a.x=aa; b.x=bb;
        calc_abp( e0.y, c0.y, e1.y, c1.y, out aa, out bb ); a.y=aa; b.y=bb;
        calc_abp( e0.z, c0.z, e1.z, c1.z, out aa, out bb ); a.z=aa; b.z=bb;
    }

    // calculation of coefficient of linear equations for a specified angle domain
    void calc_abi(vector[,] e, vector[,] c, ref vector[,] a, ref vector[,] b
                      , vector es, vector cs
                      , int i, int j)
    {
         calc_ab( e[i,j], c[i,j]
                , es, cs
                , out a[i,j], out b[i,j]);
    }

    // Scale fuction
    void resize( int S, int scale )
    {
        int i, j, w, h, D, D2,ws, hs, i2, j2, x0, y0, x1, y1, TMP, pass;
        vector v, es, cs;
        vector[,] c, e, a, b;
        int ii, jj;

        w=layers[S].Width;
        h=layers[S].Height;

        ws=w*scale;
        hs=h*scale;

        D = 1; layers[D] = new PlanarBitmap(); layers[D].New(ws,hs,3,SrcBitmap.Gamma);
        D2 = 2; layers[D2] = new PlanarBitmap(); layers[D2].New(ws,hs,3,SrcBitmap.Gamma);

        // pre-filled. for convergence
        for (i=0; i<hs; i++)
        for (j=0; j<ws; j++)
            s_SetPixel( D, j, i, s_GetPixel(S,j/scale,i/scale) );

        c = new vector[2,2]; e = new vector[2,2]; a = new vector[2,2]; b = new vector[2,2];

        for (pass=0; pass<=4; pass++)
        {
            for (i=0; i<=h/2; i++) // pass through the domain 2x2
            for (j=0; j<=w/2; j++)
            {
                i2=i*2;
                j2=j*2;

                for (ii=0; ii<=1; ii++)
                for (jj=0; jj<=1; jj++)
                {
                    c[ii,jj]=s_GetPixel( S, j2+jj, i2+ii );
                    e[ii,jj]=getSum    ( S, j2-1+jj*2,   i2-1+ii*2
                                          , j2-1+jj*2+1, i2-1+ii*2+1 );
                }
                es=new vector();
                cs=new vector();
                for (ii=0; ii<=1; ii++)
                for (jj=0; jj<=1; jj++)
                {
                    es=es+e[ii,jj];
                    cs=cs+c[ii,jj];
                }
                es=es*0.25f;
                cs=cs*0.25f;

                for (ii=0; ii<=1; ii++)
                for (jj=0; jj<=1; jj++)
                    // two linear equations:
                    // 1. angle e [ii, jj] is displayed in the angle c [ii, jj]
                    // 2. average of rank region displaying to average
                    //    domain value
                    calc_abi(e, c, ref a, ref b, es, cs, ii, jj );

                x0= j2*scale;
                x1= j2*scale+scale*2-1;
                y0= i2*scale;
                y1= i2*scale+scale*2-1;

                fill_bar( D, D2, scale
                        , x0, y0, x1, y1
                        , b, a
                        );
            }
            TMP=D; D=D2; D2=TMP;
        }
        DstBitmap.TakeOver(layers[D2]);
    }

    public override void Apply()
    {
        layers = new PlanarBitmap[3];
        layers[0] = SrcBitmap;
        resize(0,SCALE);
    }
}
Michael Vinther

> software developer <

10

Re: About upgrade of fractal interpolation plugin

If you are up for it you could also try to translate some of the Matlab code in the same way..  wink If it performs well I can include it in IA.

Michael Vinther

> software developer <

Re: About upgrade of fractal interpolation plugin

Sorry, but i'm not programmer (for this time). I will be a learn c++ in a future, but now i don't find a good teacher for me.

12

Re: About upgrade of fractal interpolation plugin

Ok, Just thought you might be because you posted source code..

Michael Vinther

> software developer <

Re: About upgrade of fractal interpolation plugin

I'm find correct way to increase quality of 2x enlargement for Fractal 9 / Xin Li.
1)Smooth image with "soft" filter (Gaussian R-0.7 pixels)
2)Sharp with 5 iteration (Deconvolution -> Blind standard settings)
3)Smooth image with "soft" filter (Gaussian R-1 Pixels)
4)Sharp with 7 iteration (Deconvolution -> Gaussian blur -> Spread = 1 pixels)
5)Apply a median filter with 2 pixels radius and fade it for 25%
6)Apply a erosion filter and fade it for 25%
---------------------------------------------------------
This way designed for landscape and forest.

14

Re: About upgrade of fractal interpolation plugin

How does that perform compared to the Wiener 4 or 6 methods in the standard resize dialog?

Michael Vinther

> software developer <

Re: About upgrade of fractal interpolation plugin

Can you understand what is it? I'm find IFS interpolation code, i think is C code.

16

Re: About upgrade of fractal interpolation plugin

I'm sorry, but I don't understand the question. Understand what is what?

In general I don't find super resolution algorithms so relevant any more, because most modern cameras provide higher resolution than I actually need..

Michael Vinther

> software developer <

Re: About upgrade of fractal interpolation plugin

Sorry for my bad  in my question wink Just I find this and want to use it with Your Script Reader plugin for interpolation. Can i make this conversion ?


Quadratic IFS
/* Quadratic IFS */
/* Example 2.4, p.210 Barnsley, Fractals Everywhere */


#include<stdio.h>

main()
{

int k,n,m,i,isize
float x1,x2,y1,y2,x,y,xpoint,ypoint,inc,a,b,
    incx,incy

FILE *ifs; /* ifs=ifs.dat*/
FILE *ifsgnu;/*ifsgnu=ifs.gnu*/
*/ READ IN THE DATA POINTS */

if ((ifs=fopen("q-ifs.dat","r"))==NULL)
printf ("This file could not be opened.\n");
else {
    fscanf (ifs,"%i\n",&m);
    printf ("Number of inner iterations = %i\n",m);
    fscanf (ifs,"%i\n",&isize);
    printf ("Number of initial coordinates = %i\n",isize);

    printf ("%i\n",m)
    fscanf (ifs,"%f%f\n",&x1,&y1);
    fscanf (ifs,"%f%f\n",&x2,&y2);
}

if ((ifsgnu=fopen("q-ifs.gnu","w"))==NULL)
    printf ("\n");

/* CALCULATIONS /*

/* Compute the left side if the line */
inc=0.05;
xpoint=x1;
ypoint=y1;

for (k=1; k<=isize;) {
    x=xpoint-(k-1)*inc;
    y=2.0*x - x*x;
for (n=0; n<=m;) {
    y=0.5*x + 0.25*y;
x=0.5*x;
    fprint (ifsgnu,"%.3f\t%.3f\n",x,y);
    n=n+1;
}
    k=k+1;
    fprintf (ifsgnu, "\n");
}

/* Compute the right side of the line */
xpoint=x1;
ypoint=y1;

for (k=1; k<=isize;) {
    x=xpoint+(k-1)*inc;
    y=2.0*x - x*x;

for (n=0; n<=m;) {i
y=-0.5*x + 0.25*y + 1.0;
    x=0.5*x + 1.0;
    fprintf (ifsgnu,"%.3f\t%.3f\n",x,y);
    n=n+1;
}
    k=k+1;
    fprintf (ifsgnu, "\n");
}


return 0;

}

18

Re: About upgrade of fractal interpolation plugin

As far as I can tell this code that you have posted just writes some numbers to a file, it does not process a full image. Therefore it probably   doesn't make sense to use as a plugin.

Michael Vinther

> software developer <

Re: About upgrade of fractal interpolation plugin

If you are still interested in this topic...

Several years ago, I've discovered someone's diploma thesis from the mid 90-s - a C++ implementation of fractal image compression using Quad Tree (?). It just took a 8bit grayscale image in a raw binary format, compressed it a decompressed with the choice of target size.

I wrote a REALLY STUPID command line interface which accepts 24bit BMP image. It splits the image into several tiles as the algorithm crashes at bigger images. From each tile there are RGB channels separated, then (optionally) converted to YUV as it does not cause so much visible colour artifacts, compressed and decompressed into desired size, converted back to RGB and finally the upscaled tiles are stitched into target BMP.

It produces really sharp results on natural structures (wood, grass...) and can be used escpecially for landscape photography upscaling.

See https://skydrive.live.com/redir.aspx?ci … parid=root

All images are upscaled 3x which is problem for most algorithms I know.
Each image was upscaled in approx. 1 - 2 minutes (one 2.5GHz core used).

If you consider it worth playing with, I can provide you with the source code. It should be rewritten as it still uses temporary files on disk for compression/decompression. I didn't put much effort in it...

20

Re: About upgrade of fractal interpolation plugin

I might get back to this topic, but right now I'm working on a number of other things..

Michael Vinther

> software developer <

21 (edited by deltaelite 2012-03-27 17:32:30)

Re: About upgrade of fractal interpolation plugin

Hello,
to say at first i have no skills in mathematics :-).
About 3 years ago i had the idea of using the "brute force" method to recalcualate
the original image data which usually gets lost after JPEG compression.
I thougt it could be easily with experimenting on a 128x128 pixel image which contains
a RGB color gradient.
Then i compress the image at different compression Levels and see the difference
(subtraction, or comparsion with maybe with FFT,wavlet and others)
which could maybe result in a mathematical formula which could be used to have a direction to get faster bruteforce results.
So this idea is like the deconvolution just for color information which is lost by compression.

when i saw the fractal upscaling artefacts, this idea came back to my mind.
I think these artefacts are the results of the JPEG artefact in the input image.
Offcourse they look more like sharpening artefacts but i guess this is the transformation
of the JPEG artefacts that came from the fractal interpolation.

Maybe you could try your fractal method on an uncompressed input image from a scanner for example
and use a uncompressed file format like scannedimage.bmp (or png, or tif)
Then save result with your fractal resizing method.
After this save your "scannedimage.bmp" as a jpeg file (quality 90 for example)
and resize this image too at the same way and save the result.
Now you could compare the both against each other, i am interested too,
it would nice if you could post the 3 images (original,original-fractal,jpeg-fractal)

So maybe the solution is to use or implement a working JPEG filter.
(the normal JPEG filter doesnt work good, the result is a very very small difference)
Also the method with erosion and deconvolution results back in to the compression artefacts.

I made a quick comparsion (ZOOMED at 500% ):
http://img190.imageshack.us/img190/1074/farbkreisvergleich5xzoo.png
i drawed some line for better comparsion:
http://img441.imageshack.us/img441/8176/farbkreisfrequencydomai.jpg
http://img140.imageshack.us/img140/8673/farbkreisfftvergleich.jpg

Uploaded with ImageShack.us

maybe a frequency interpolation based on the "hamonics" (example sine waves)
could stretch the spectrum back to the original? I mean something like the histogrammstreching
only converted to the frequency domain level. (i came on the idea because the image of my comparsion looks like a graphical frequency equalizer, only upside down)
The problem is that it is possible to delete information with the FFT and the frequency domain filter,
so there must be a way to draw the lost information by iteration/interpolation?

Just my brainstorming ideas :-)

SPAM POSTS DELETED: 116

22 (edited by Adam 2012-03-29 19:35:29)

Re: About upgrade of fractal interpolation plugin

Hello deltaelite,

I'm not sure if I can understand, but - I don't think that reducing jpeg artifact will help a lot.
(I know about them - that's why I use JPEG2000 for storing my photographs from SLR instead.)

If you want to play with that command-line utility, I put the zipped binary at the same place where have been the original pictures.

The executable is standard win32. (It works under Linux/wine as well.)

In qtresize.cfg there are best "value for money" settings from my experiments. Changing them will probably prolong the processing time, worsen the results or crash the program. But you are free to play with them.

You don't need the scale1.sh (.bat).

Just type:
qtresize yourimage.bmp n

where n is target scale 2, 3, 4...
Only bmp is supported.

23 (edited by deltaelite 2012-03-30 15:34:03)

Re: About upgrade of fractal interpolation plugin

Hello,
i suggested the idea to remove the jpeg artefacts, because every image interpolation
amplifies also the uwanted distortions like JPEG Artefacts and noise.
I will try to deliver exaple images to show if ther is a differnce.
What is the best fratal method in IA (and best value sttings?)
did someone already made a test series?

Your suggestion to use JPEG2000 instead of JPEG is ok,
but i think JPEG2000 needs to be implemented in hardware (Consumer Cameras)
before it is able to replace the old JPG standart. (which is really needed i think!)


For me it makes no sence to use, i use uncompressed images or
i get JPEG Files from my Camera (I also could use raw if needed...)
so recrompression JPEG-Files to jpg2000 makes only an additional quality loss.
If Quality AND compression is needed it is possible to compress the lossless
formats with the implementet runtimnes (example LZ77,RLE) or better
with zip,rar, or 7zip.

greets

SPAM POSTS DELETED: 116

Re: About upgrade of fractal interpolation plugin

Adam wrote:

Hello deltaelite,

I'm not sure if I can understand, but - I don't think that reducing jpeg artifact will help a lot.
(I know about them - that's why I use JPEG2000 for storing my photographs from SLR instead.)
.....

Ok i played some hours around to find some answers, and like i guessed before i was right.
The JPEG artefacts disturb the process of fractal interpolation even at a high quality of 95%
this is visible like i demonstrate here:

http://img23.imageshack.us/img23/4324/farbkreis.png

at first the original uncompressed image scaled up (just for the better visible comparsion) with 3x pixel method:
http://img829.imageshack.us/img829/2861/farbkreispixel3x.png

now the fractal9squared resized image (3x , region=14 regul=0,00000488 filter=4 clampw=0 normalize=0 clampres=1)
http://img32.imageshack.us/img32/5382/farbkreisfractal9x3regi.png

and now the original image saved as JPEG (95% Quality) and then resized with the fractal9squared method (same parameter as before):
http://img11.imageshack.us/img11/7786/farbkreisq95pfractal9x3.png

the line between red and mauve is visibly disturbed, to my suprise i cant see the artefacts here on my cheap TFT Screen.
I sawed them before on a quality CRT-Monitor. TFTs are known for limited color abilitys.. ;-)
But neverless, in fact a loss of fine details is visible. (the fine lines of the original image are lost)

Ok i will try it with a 75% Quality JPEG:

http://img850.imageshack.us/img850/3168/farbkreisq75pfractal9x3.png

ok now i can see the stair-like artefacts on my cheap TFT (just my internet PC, not for graphics...)

so in figured out that the JPEG-compressed image limits the ability of the resize algorithm,
if something like an iteration of the original Image Colors and gradients would be a big advantage to the fractal interpolation. The idea like a database of the university with that superresolution (with learing samples)
are similar what i would do to solve the problem.
It is like the bruteforce Method but faster like BF with rainbowtables.


The Artefacts of your image you posted before are from the jpeg-compression.
I got similar results with your images.
What method and parameters did you use?

i also did a comparsion of the IA fractal resizing algorithms at 3x scaling
vs. onOne Genuine Fractals 6 Pro as "The industry standard for image resizing"=159eur and
vs. BenVista PhotoZoom Pro 4 with "patented S-Spline Technology"=169eur

guess which one produced the best results
;-) LOL

SPAM POSTS DELETED: 116

Re: About upgrade of fractal interpolation plugin

I missed something? smile I was not on this forum for 3 months and I am shocked seen. And I not know what such a method of image interpolation can be increased by more than 2 times without visible artifacts. But even more liked work of Adam.