Skip to main content

Making a GUI in dm-script

 // 2 button dialog example 

// To invert the most front image.

// Modified from http://www.dmscripting.com/files/Example_Button_Enabling_Dialog.s

// Renfong

// 2021/03/24



// Global variables

taggroup firstbutton, secondbutton

number true=1

number false=0

image src



// the class createbuttondialog is of the type user interface frame (UIFrame), and responds to interactions

// with the dialog - in this case pressing buttons


class CreateButtonDialog : uiframe {

void button1response(object self) {


//the response when the button is pressed

self.SetElementIsEnabled("first", false); // these commands set the button as enabled or not enabled

self.SetElementIsEnabled("second", true); // "second" in this command is the identifier of the button 'secondbutton'


// put action1 here

src.GetFrontImage()

result(src.GetName()+" is picked.\n")

};


void button2response(object self) {


//the response when the second button is pressed

self.SetElementIsEnabled("first",true);

self.SetElementIsEnabled("second",false);

// put action2 here

image invert

invert = src

invert = max(src)-invert

invert.SetName("Invert of "+src.GetName())

invert.ShowImage()

};

}



// this function creates a button taggroup which returns the taggroup 'box' which is added to

// the dialog in the createdialog function.


taggroup MakeButton() {


// Creates a box in the dialog which surrounds the button

taggroup box_items

taggroup box=dlgcreatebox("", box_items)

box.dlgexternalpadding(5,5)

box.dlginternalpadding(25,25)


// Creates the first button

firstButton = DLGCreatePushButton("Get Front Image", "button1response")

DLGEnabled(firstbutton,1) // sets the button as enabled when the dialog is first created

DLGIdentifier(firstbutton, "first") // identifiers are strings which identify an element, such as a button

// they are used to change the enabled/disabled status of the element in the button response functions above

firstbutton.DLGExternalPadding(10,0)

box_items.DLGAddElement(firstbutton)


// Creates the second button

secondbutton = DLGCreatePushButton("Show Invert", "button2response")

DLGEnabled(secondbutton,0)

DLGIdentifier(secondbutton, "second")

secondbutton.DLGExternalPadding(5,10)

box_items.DLGAddElement(secondbutton)

return box


};


// This function creates the dialog, drawing togther the parts (buttons etc) which make it up

// and alloc 'ing' the dialog with the response, so that one responds to the other. It also

// displays the dialog


void CreateDialog() {


// Configure the positioning in the top right of the application window

TagGroup position;

position = DLGBuildPositionFromApplication()

position.TagGroupSetTagAsTagGroup( "Width", DLGBuildAutoSize() )

position.TagGroupSetTagAsTagGroup( "Height", DLGBuildAutoSize() )

position.TagGroupSetTagAsTagGroup( "X", DLGBuildRelativePosition( "Inside", 1 ) )

position.TagGroupSetTagAsTagGroup( "Y", DLGBuildRelativePosition( "Inside", 1 ) )


TagGroup dialog_items;

TagGroup dialog = DLGCreateDialog("Do invert", dialog_items).dlgposition(position);


dialog_items.DLGAddElement( MakeButton() );


object dialog_frame = alloc(CreateButtonDialog).init(dialog)

dialog_frame.display("Invet Image");

};



// calls the above function which puts it all together

CreateDialog()


============================================

result:



Comments

Popular posts from this blog

Top hat filter

The top_hat filter can be used to detect the relatively small edges/peaks superimposed on large background signals. The concept came from the EELS workshop during IMC19. Thanks to Prof. Nestor J. Zaluzec. -- // Using Top_hat digital filter to detect the  relatively small edges  //    superimposed on large background signals. // // ref: Ultramicroscopy 18 (1985) 185-190  //      Digital Filters  for Application to Data Analysis in EELS //      by Nestor J. ZALUZEC // Parameters: // win_s: signal window (default:3) // win_b: background window (default:3) //  a_s : amplitude of signal (fixed value) //  a_b : amplitude of background  (fixed value) // Renfong 2018/10/11 // Main function image Top_Hat_Filter(image img, number win_s, number win_b) { // read image string fname=img.GetName() number sx,sy img.getsize(sx,sy) // filter image img2 := imageclone(img)*0 //the area between...

MLLS in matlab

MLLS stands for  multiple linear least squares fitting, which is the common strategy for the solving EELS edge overlapping and which is also built-in the GMS software. The target spectrum Y and the reference spectrum X Y = A * X Assuming Y is 1*256 matrix and we have three reference spectrums, ie, X is 3*256 matrix. So A is 1*3 matrix. The target is to solve A. If Y and X are n*n matrices, we can use the simple formula Y * inv(X) = A * X * inv(X), ie., A = Y * inv(X). However, Y and X are not n*n  matrices, it is necessary to have some trick to solve it. We can multiply the transpose matrix to produce n*n matrix. Y * X' = A * X * X'  (ps X' means the transpose matrix of X) so A = Y * X' * inv(X * X') Here is the Matlab code: =========  % create target spectrum x=0:256; c=[90,120,155]; sig=[5,10,8]; int=[5,10,8]; xn=zeros(size(x)); ref=zeros(length(c),length(x)); factor=rand(size(c))'; for i=1:length(c)     xn=xn+int(i)*ex...

Drift correction in Matlab

In order to improve S/N ratio, microscopist uses several short acquisition time images, and then sum them up. So the drift correction is very important. Here is the demo of how to use Matlab do drift correction. In the first, load an image, and using circshift function to shift the object in the image. Then use fft cross correlation to compute the moving distance. Finally, shift the object to the origial position. Here is the testing code: == % Demo of drift correction % 2018/11/15  by Renfong im1= imread('cameraman.tif');    % reference image [sy,sx]=size(im1); % shift the object im2=circshift(im1,[20,10]);    % the object moved down 20 pixels and moved right 10 pixels. figure(1); subplot(121);imshow(im1); subplot(122);imshow(im2); % Using fft cross correlations to detect the moving distance[1] fftim1=fft2(im1); fftim2=fft2(im2); cc=fftshift(ifft2(fftim1.*conj(fftim2))); [shiftY,shiftX]=find(cc==max(cc(:))...