Scripting Resources for DigitalMicrograph™ |
Apply CLUT |
|
Function |
Applies a custom colour lookup table to the foremost image and a floating scale which shows the range of colours present. |
Version |
version:20040401, v1.1 |
Author |
D. R. G. Mitchell |
Acknowledgements |
|
Comments |
Useful for highlighting subtle intensity variations, which are much more evident in colour than greyscale. Uses only internally generated CLUTs, so no external dependencies. Images with CLUTs are indexed colour and need to be changed to RGB manually (Edit/Chane Data Type) if that format is required. The colour scale bar can be stretched moved or deleted as required. |
System Requirements |
Should be compatible with all recent versions of DigitalMicrograph. |
Known Issues |
|
Supported |
Yes. |
Included Files |
Single script file. |
Source Code |
// This script uses a dialog to allow the user to apply a custom // colour lookup table (CLUT) to the foremost image. // All the CLUTs are generated within the script so there is // no external dependency on CLUT images stored in the system. // Images with custom CLUTs applied are not coonverted into RGB images // by this script. Images will need to be converted to RGB using the menu // command Edit/Change Data Type . . . and selecting RGB // Colouring greyscale images can be very useful for highlighting subtle // variations in greyscale such as in thickness maps. The reason for this // is that our eyes are only sensitive to about 30 greyscale levels, but // 16 million colours. The scale pasted on the image floats, and can be // stretched, repositioned or deleted.
// version:20040401
// D. R. G. Mitchell, adminnospam@dmscripting.com (remove the nospam to make this email address work)
// Version 1.1
image frontimg:=getfrontimage() setsurveytechnique(frontimg, 0) rgbImage customCLUT := RGBImage("CLUT", 4, 256, 1) imagedisplay imgdisp=imagegetimagedisplay(frontimg,0)
// Variables
string returnstring string specimen number xsize, returnno, ysize, scalesize=256 number contrastlo, contrasthi, contrastmid
//Define the dialogue class
class Dialog : uiframe {
void trackchange( object self, TagGroup tg) { returnno=val(dlggetstringvalue(tg))-1 dlggetnthlabel(tg, returnno, returnstring) } }
// Create the tags which define the dialog pane
TagGroup dialog = DLGCreateDialog("Select CLUT");
TagGroup popup = DLGCreatePopup(1, "trackchange")
// Simply copy the line as shown below to add more users popup.DLGAddPopupItemEntry("Temperature"); popup.DLGAddPopupItemEntry("Rainbow"); popup.DLGAddPopupItemEntry("Greyscale");
popup.DLGAddPopupItemEntry("Red"); popup.DLGAddPopupItemEntry("Green"); popup.DLGAddPopupItemEntry("Blue");
popup.DLGAddPopupItemEntry("Yellow"); popup.DLGAddPopupItemEntry("Cyan"); popup.DLGAddPopupItemEntry("Magenta");
popup.DLGIdentifier("Popup") dialog.DLGAddElement( popup )
// sets the returnstring to the first item in the list of CLUTs
returnno=val(dlggetstringvalue(popup))-1 dlggetnthlabel(popup, returnno, returnstring)
// Display the dialog
object dialog_frame = alloc(Dialog).init(dialog) if(!dialog_frame.pose()) exit(0)
// Based on the value returned by the Dialog, the CLUT selected is applied
if(returnstring=="Temperature") { Image wedgeScale := RealImage("Grayscale", 4, 256, 1) wedgescale=(icol<128) ? 256-(icol*2) : (icol-128)*2 wedgescale=wedgescale/255
customclut=rgb(255*(icol/255), 255*wedgescale*(icol/255),0) imagedisplaysetinputcolortable(imgdisp, customclut) }
if(returnstring=="Red") { customclut=rgb(255*(icol/256),0,0) imagedisplaysetinputcolortable(imgdisp, customclut) }
if(returnstring=="Green") { customclut=rgb(0,255*(icol/256),0) imagedisplaysetinputcolortable(imgdisp, customclut) }
if(returnstring=="Blue") { customclut=rgb(0, 0,255*(icol/256)) imagedisplaysetinputcolortable(imgdisp, customclut) }
if(returnstring=="Yellow") { customclut=rgb(255*(icol/256),255*(icol/256),0) imagedisplaysetinputcolortable(imgdisp, customclut) }
if(returnstring=="Cyan") { customclut=rgb(0,255*(icol/256),255*(icol/256)) imagedisplaysetinputcolortable(imgdisp, customclut) }
if(returnstring=="Magenta") { customclut=rgb(255*(icol/256),0,255*(icol/256)) imagedisplaysetinputcolortable(imgdisp, customclut) }
if(returnstring=="Greyscale") { customclut=rgb(255*(icol/256),255*(icol/256),255*(icol/256)) imagedisplaysetinputcolortable(imgdisp, customclut) }
if(returnstring=="Rainbow") { image redcycle:=realimage("cycle",4,256,1) image greencycle:=realimage("cycle",4,256,1) image bluecycle:=realimage("cycle",4,256,1)
redcycle=cos((icol/295)*pi()*2)*2+1 greencycle=(sin((255-icol/200)*pi()*2-1)+.75)/2 bluecycle=sin((255-icol/280)*pi()*2)*2
customclut=rgb(255*redcycle,255*greencycle,255*bluecycle) imagedisplaysetinputcolortable(imgdisp, customclut) }
// Get some info on the foremost image
showimage(frontimg) setwindowposition(frontimg, 142,24)
getsize(frontimg, xsize, ysize) if(ysize>255) scalesize=128 if(ysize>511) scalesize=256
// A vertical colour scale is created from the CLUT generated above
image scale=rgbimage("",4,30*(scalesize/256), scalesize) scale=customclut[(scalesize-irow)*(256/scalesize),icol]
// The contrast values in the image are extracted to annotate the scale with
imagedisplaygetcontrastlimits(imgdisp, contrastlo, contrasthi) contrastmid=contrastlo+((contrasthi-contrastlo)/2)
// The image scalepaste is temporary image in which the scale and annotations // are assembled before being pasted onto the foremost image
image scalepaste=rgbimage("",4,85, scalesize+10) scalepaste=0 showimage(scalepaste)
// Scaleoutline creates a white border around the scale image
image scaleoutline=rgbimage("",4,(30*(scalesize/256))+2, scalesize+2) scaleoutline=rgb(255,255,255) showimage(scaleoutline) scrapcopy(scaleoutline) deleteimage(scaleoutline)
scrappaste(scalepaste) scrapsetlocation(scalepaste, 4,4) scrapmerge(scalepaste)
// The scale image is pasted into the scalepaste temporary image
showimage(scale) scrapcopy(scale) deleteimage(scale)
scrappaste(scalepaste) scrapsetlocation(scalepaste,5, 5) scrapmerge(scalepaste)
// The vertical scale is annotated with the hi, lo and mid contrast values // from the foremost imagee.
number annot1=createtextannotation(scalepaste, 0, 40, ""+format(contrasthi,"%4.3f")) setannotationsize(scalepaste,annot1, 12)
number annot2=createtextannotation(scalepaste, scalesize-10, 40, ""+format(contrastlo,"%4.3f")) setannotationsize(scalepaste,annot2, 12)
number annot3=createtextannotation(scalepaste, (scalesize/2)-5, 40, ""+format(contrastmid,"%4.3f")) setannotationsize(scalepaste,annot3, 12)
// The assembled scalepaste image is copied and pasted onto the foremost image scrapcopy(scalepaste) scrappaste(frontimg) deleteimage(scalepaste) scrapsetlocation(frontimg, 30,30) |