I am currently developing a function for edge detection in DigitalMicrograph (DM) scripting. I already have two simple implementations to calculate the first and second derivatives using intrinsic variables, as shown below:
First derivative:
Image absolute_first_derivative(Image in)
{
Number size_x, size_y, origin, scale;
String units;
Image out;
in.ImageGetDimensionCalibration(0, origin, scale, units, 0);
in.GetSize(size_x, size_y);
if (size_y != 1) Result("Only compatible with 1D image");
out := RealImage("first_derivative", 4, size_x, size_y);
out = in[icol + 1, irow] - in[icol, irow];
out[0, 0] = 0;
out[size_x - 1, 0] = 0;
out.ImageSetDimensionCalibration(0, origin, scale, units, 0);
return out;
}
Second derivative:
Image second_derivative(Image in)
{
Number size_x, size_y, origin, scale;
String units;
Image out;
in.ImageGetDimensionCalibration(0, origin, scale, units, 0);
in.GetSize(size_x, size_y);
if (size_y != 1) Result("Only compatible with 1D image");
out := RealImage("second_derivative", 4, size_x, size_y);
out = in[icol + 1, irow] - 2 * in[icol, irow] + in[icol - 1, irow];
out[0, 0] = 0;
out[size_x - 1, 0] = 0;
out.ImageSetDimensionCalibration(0, origin, scale, units, 0);
return out;
}
I would like to implement a more flexible, kernel-based approach (e.g., Sobel, LoG or similar kernels) using the Warp()
function provided by DM. However, it appears that Warp()
is explicitly designed for 2D image transformations.
My questions are:
- Can
Warp()
in DigitalMicrograph script be adapted or used for 1-dimensional image processing? - If
Warp()
is not suitable, is there another built-in DM function or recommended method to perform kernel-based convolution or transformations specifically on 1D images?
Any suggestions or examples would be greatly appreciated!
I am currently developing a function for edge detection in DigitalMicrograph (DM) scripting. I already have two simple implementations to calculate the first and second derivatives using intrinsic variables, as shown below:
First derivative:
Image absolute_first_derivative(Image in)
{
Number size_x, size_y, origin, scale;
String units;
Image out;
in.ImageGetDimensionCalibration(0, origin, scale, units, 0);
in.GetSize(size_x, size_y);
if (size_y != 1) Result("Only compatible with 1D image");
out := RealImage("first_derivative", 4, size_x, size_y);
out = in[icol + 1, irow] - in[icol, irow];
out[0, 0] = 0;
out[size_x - 1, 0] = 0;
out.ImageSetDimensionCalibration(0, origin, scale, units, 0);
return out;
}
Second derivative:
Image second_derivative(Image in)
{
Number size_x, size_y, origin, scale;
String units;
Image out;
in.ImageGetDimensionCalibration(0, origin, scale, units, 0);
in.GetSize(size_x, size_y);
if (size_y != 1) Result("Only compatible with 1D image");
out := RealImage("second_derivative", 4, size_x, size_y);
out = in[icol + 1, irow] - 2 * in[icol, irow] + in[icol - 1, irow];
out[0, 0] = 0;
out[size_x - 1, 0] = 0;
out.ImageSetDimensionCalibration(0, origin, scale, units, 0);
return out;
}
I would like to implement a more flexible, kernel-based approach (e.g., Sobel, LoG or similar kernels) using the Warp()
function provided by DM. However, it appears that Warp()
is explicitly designed for 2D image transformations.
My questions are:
- Can
Warp()
in DigitalMicrograph script be adapted or used for 1-dimensional image processing? - If
Warp()
is not suitable, is there another built-in DM function or recommended method to perform kernel-based convolution or transformations specifically on 1D images?
Any suggestions or examples would be greatly appreciated!
Share asked 23 hours ago Samuel HaoSamuel Hao 233 bronze badges New contributor Samuel Hao is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.1 Answer
Reset to default 2The main purpose of the Warp() function is to do interpolations into an existing data array or image, so it seems that its usage is secondary to your main goal of doing kernel-based filtering of 1D data arrays. Consequently, this answer approaches your question in two stages.
The first stage is simply to carry out kernel-based computation. This is readily achieved with the DM Convolution() function, as illustrated in the following example which applies a smoothing first-derivative kernel to some target data:
Number kernelHalfWidth = 2;
Image kernel := RealImage("Kernel", 4, 2 * kernelHalfWidth + 1);
kernel = (icol < kernelHalfWidth) ? -1 : ((icol > kernelHalfWidth) ? 1 : 0);
kernel.ShowImage();
Number arraySize = 512;
Image targetArray := RealImage("Target", 4, arraySize);
Image resultArray := RealImage("Result", 4, arraySize);
Number period = arraySize / 4;
targetArray = Sin(2 * Pi() * icol / period);
resultArray = targetArray.Convolution(kernel);
targetArray.ShowImage();
resultArray.ShowImage();
Unfortunately, the DM help documentation does not cover the Convolution() function in great detail, but there are a few example scripts for it and other image filtering functions provided in the section Scripting>Example Scripts>Simple Image Computation>Image filtering.
If you do a search for "[dm-script] Convolution" within StackOverflow, you will find a couple of other posts that also touch on the use of this and related functions with DM scripting.
As for your desire to use the Warp() function, this seems like a separate issue, since its purpose is mainly to interpolate values within an array, which could be done either before or after you apply the Convolution function. If you still have a question about Warp, please make that a separate post.