Scripting Resources for DigitalMicrograph™

banner

Dave Mitchell's DigitalMicrograph™ Scripting Website

Home | Scripts | Examples | Functions | Recent Updates | Tutorials | Resources | Publications | Consulting | Projects | Contact & Bio |PyJEM| Search

 

7 x 7 Mexican Hat
Function
Applies a 7 x 7 Mexican Hat kernel to the foremost image. This Laplacian of Gauassians is an efficient edge detector without being too sensitive to noise.
Version
version:20030301
Author
D. R. G. Mitchell
Acknowledgements

These tyype of image processing tools are described in John Russ' 'The Image Processing Handbook'.

Comments
System Requirements
Compatible with all DM versions, including old Mac-based systems.
Known Issues
It is a big kernel and on a large image will be quite slow.
Supported
Yes.
Included Files
Single script.
Source Code

// Filter to compute a Mexican Top Hat Filtered Image

// Note - this is a slow operation.

// Dave Mitchell, nospamadmin@dmscripting.com (remove the nospam to make email address this work)

// March 2003

// version:20030301

// v2.0

 

// Variables

 

realimage front

front:=getfrontimage()

showimage(front)

setwindowposition(front,142,24)

updateimage(front)

 

string unitstring

number scalex, scaley

getunitstring(front, unitstring)

getscale(front, scalex, scaley)

 

number xsize=0, ysize=0

getsize(front,xsize,ysize)

string name = getname(front)

string newname = "7x7 Mex Hat of " + name

if(len(newname)>31) newname=left(newname,31)

 

number adderx, addery

number pixelvalue=0

number counter=0

 

image kernel

image sumimage:=integerimage(newname, 4,1, xsize, ysize)

sumimage=0

 

// Definition of a 7x7 Mexican Hat Kernel

 

kernel := [7,7]:

{

{0,0,-1,-1,-1,0,0 },

{0,-1,-3,-3,-3,-1,0 },

{ -1,-3,0,7,0,-3,-1},

{ -1,-3,7,24,7,-3,-1},

{-1,-3,0,7,0,-3,-1},

{ 0,-1,-3,-3,-3,-1,0},

{0,0,-1,-1,-1,0,0 }

}

 

sumimage=Exprsize(xsize,ysize,0)

 

// Obtain the values from the kernel image

 

For (adderx=1; adderx<8;adderx++)

{

For(addery=1;addery<8;addery++)

{

pixelvalue=getpixel(kernel, adderx-1, addery-1)

sumimage=sumimage+(offset(front,adderx-4,addery-4)*pixelvalue)

counter=counter+1

openandsetprogresswindow("Working on:","X Pass "+adderx+" of 7","Y Pass "+addery+" of 7")

}

}

 

showimage(sumimage)

setwindowposition(sumimage,170,54)

converttoshort(sumimage)

openandsetprogresswindow("","","")

 

setscale(sumimage,scalex,scaley)

setunitstring(sumimage,unitstring