## Denoise

Expand Messages
• I wanted to implement a very interesting denoise routine using min max curvature. It is described here:
Message 1 of 8 , Feb 1, 2003
• 0 Attachment
I wanted to implement a very interesting denoise routine using min max
curvature. It is described here:
http://www.math.berkeley.edu/~sethian/Applets/java_files_denoising/image_denoising.java.main.html

http://www.math.berkeley.edu/~sethian/Papers/sethian.minmaxmean.ps.gz
http://www.math.berkeley.edu/~sethian/Papers/sethian.unified.ps.gz

Thanks
Martin

#include <math.h>
#include <stdlib.h>
#include <stdio.h>

double * doubledata;

#define Pixel(x,y) (doubledata[(y)*width+(x)])

#define EPSLON 1.0e-5

static double K(int width, int height, int x,int y)
{
double nx,ny;
double nxx,nyy,nxy;
double length;
double tmp;
int ix[2],iy[2];

if((x>=1)&&(x<width-1)){
nx = 0.5*(Pixel(x+1,y)-Pixel(x-1,y));
nxx = Pixel(x+1,y)-2*Pixel(x,y)+Pixel(x-1,y);
ix[0]=x-1;
ix[1]=x+1;
}
else if (x==0){
nx = Pixel(x+1,y)-Pixel(x,y);
nxx = 0;
ix[0]=x;
ix[1]=x+1;
}
else{
nx = Pixel(x,y)-Pixel(x-1,y);
nxx = 0;
ix[0]=x-1;
ix[1]=x;
}

if((y>=1)&&(y<height-1)){
ny = 0.5*(Pixel(x,y+1)-Pixel(x,y-1));
nyy = Pixel(x,y+1)-2*Pixel(x,y)+Pixel(x,y-1);
iy[0]=y-1;
iy[1]=y+1;
}
else if (y==0){
ny = Pixel(x,y+1)-Pixel(x,y);
nyy = 0;
iy[0]=y;
iy[1]=y+1;
}
else{
ny = Pixel(x,y)-Pixel(x,y-1);
nyy = 0;
iy[0]=y-1;
iy[1]=y;
}
nxy = (Pixel(ix[1],iy[1])-Pixel(ix[0],iy[1])-
Pixel(ix[1],iy[0])+Pixel(ix[0],iy[0]))
/((ix[1]-ix[0])*(iy[1]-iy[0]));

length = sqrt(pow(nx*nx+ny*ny,3));
if(length<EPSLON)
return 0;
tmp = nxx*ny*ny-2*nx*ny*nxy+nyy*nx*nx;
tmp = tmp/length;
return tmp;
}

static double F(int width, int height, double T, int x,int y)
{
double total;
double tmp;
int i,j;
int num;
double c;

total = 0;
num = 0;
for(j=-1;j<=1;j++)
for(i=-1;i<=1;i++){
if((x+i>=width)||(x+i<0))
continue;
if((y+j>=height)||(y+j<0))
continue;
total += Pixel(x+i,y+j);
num++;
}
tmp = total/num;

c = K(width, height, x,y);
if(tmp < T)
return max(c,0);
else
return min(c,0);
}

static void init(unsigned char *data, int width, int height)
{
int i,j;

if(doubledata!=NULL){
free(doubledata);
}
doubledata = (double *)malloc(sizeof(double)*width*height);
if(doubledata==NULL){
printf("Out of memory\n");
}

for(j=0;j<height;j++)
for(i=0;i<width;i++){
Pixel(i,j) = (double)data[j*width+i];
}
}

double Dx1(int width, int height, int x, int y)
{
if(x>=1){
return(Pixel(x,y)-Pixel(x-1,y));
}
else
return 0;
}

double Dx2(int width, int height, int x, int y)
{
if(x<width-1){
return(Pixel(x+1,y)-Pixel(x,y));
}
else
return 0;
}

double Dy1(int width, int height, int x, int y)
{
if(y>=1){
return(Pixel(x,y)-Pixel(x,y-1));
}
else
return 0;
}

double Dy2(int width, int height, int x, int y)
{
if(y<height-1){
return(Pixel(x,y+1)-Pixel(x,y));
}
else
return 0;
}

double levelset(int width, int height, double tstep, double T, int x,
int y)
{
double tmp;
double nabla1,nabla2;
double a1,a2,a3,a4,a5,a6,a7,a8;
double f;

a1 = max(Dx2(width, height, x,y),0);
a2 = min(Dx1(width, height, x,y),0);
a3 = max(Dy2(width, height, x,y),0);
a4 = min(Dy1(width, height, x,y),0);
nabla1 = sqrt(a1*a1+a2*a2+a3*a3+a4*a4);

a5 = min(Dx2(width, height, x,y),0);
a6 = max(Dx1(width, height, x,y),0);
a7 = min(Dy2(width, height, x,y),0);
a8 = max(Dy1(width, height, x,y),0);
nabla2 = sqrt(a5*a5+a6*a6+a7*a7+a8*a8);

f = F(width, height, T,x,y);

tmp = Pixel(x,y)-tstep*(max(f,0)*nabla2+min(f,0)*nabla1);
return tmp;
}

void denoise(unsigned char *data, int width, int height, double T,
double tstep, double totaltime)
{
double cTime;
int i,j;

init(data, width, height);
cTime = 0;
while(cTime<totaltime){
for(j=0;j<height;j++)
for(i=0;i<width;i++){
Pixel(i,j) = levelset(width, height, tstep,T,i,j);
}
cTime+=tstep;
}

for(j=0;j<height;j++)
for(i=0;i<width;i++){
data[j*width+i] = ((int)Pixel(i,j))&0xff;
}
}
• Hi all, during the developement of AutoTrace I was often asked what do do with noisy pictures. Till know I was not able to develope a really good denoising
Message 2 of 8 , May 9, 2005
• 0 Attachment
Hi all,

during the developement of AutoTrace I was often asked what do do with
noisy pictures. Till know I was not able to develope a really good
denoising tool myself. Some time ago I found a tool called
PictureCooler. Currently it's usage is free. After extensively testing
I found that it is better than other commercially available tools such
as Noiseware or Noise Ninja. Here you find it:
http://members.chello.nl/r.kroonenberg2/

Greetings
Martin
• Sorry, here is the correct link: http://denoiser.shorturl.com/ ... with ... testing ... such
Message 3 of 8 , May 9, 2005
• 0 Attachment
Sorry, here is the correct link:
http://denoiser.shorturl.com/

--- In autotrace@yahoogroups.com, "martweb2000" <martweb@g...> wrote:
> Hi all,
>
> during the developement of AutoTrace I was often asked what do do
with
> noisy pictures. Till know I was not able to develope a really good
> denoising tool myself. Some time ago I found a tool called
> PictureCooler. Currently it's usage is free. After extensively
testing
> I found that it is better than other commercially available tools
such
> as Noiseware or Noise Ninja. Here you find it:
> http://members.chello.nl/r.kroonenberg2/
>
> Greetings
> Martin
Your message has been successfully submitted and would be delivered to recipients shortly.