Commit 849b916d authored by Andrey Filippov's avatar Andrey Filippov

added imagej macros

parent a602300e
macro "cross_offset" {
saveSettings;
jpeg_directory = "/media/elphel/SSD3-4GB/lwir16-proc/berdich/annotations/collages/pattern-matching/exported_layers_on_grey";
// scoremaps_directory="/media/elphel/SSD3-4GB/lwir16-proc/berdich/annotations/collages/pattern-matching/scoremaps";
// results_directory="/media/elphel/SSD3-4GB/lwir16-proc/berdich/annotations/collages/pattern-matching/cross_offset";
// scoremaps_blurred
// scoremaps_directory="/media/elphel/SSD3-4GB/lwir16-proc/berdich/annotations/collages/pattern-matching/scoremaps_sharp";
// results_directory="/media/elphel/SSD3-4GB/lwir16-proc/berdich/annotations/collages/pattern-matching/cross_offset_sharp";
// used old files for now
scoremaps_directory="/media/elphel/SSD3-4GB/lwir16-proc/berdich/annotations/collages/pattern-matching/scoremaps_blurred";
results_directory="/media/elphel/SSD3-4GB/lwir16-proc/berdich/annotations/collages/pattern-matching/cross_offset_blurred";
//L3-1691017293_032075-7285_82.jpeg
scoremaps_suffix="-scoremap";
norm_radius = 20;
thresh0 = 0.6;
thresh1 = 0.7;
sigma = 10.0;
min_height= -0.1;
max_height= 0.25;
maxmin_min = 82.0; //difference between local maximum and local minimum (norm_radius) should be not less than this
maxmin_max = 150; //difference between local maximum and local minimum (norm_radius) should be not more than this
maxmin_rad = 15.0
// for illustrations - run for one pair with disabled close() in the end
// scale_prod=-40000 to get meters of height (depends on image offset), negative if first image is taken from higher point on the image map
// negative disparity
getCrossOffset("L3-1691017293_032075-7285_82.jpeg", "L3-1691017285_820540.jpeg", -0.060, 0.998, 300, norm_radius, thresh0, sigma, thresh1, min_height, max_height, scoremaps_directory, scoremaps_suffix, jpeg_directory, results_directory, maxmin_min, maxmin_max, maxmin_rad);
getCrossOffset("L3-1691017285_820540.jpeg","L3-1691017293_032075-7285_82.jpeg", 0.060, -0.998, 300, norm_radius, thresh0, sigma, thresh1, min_height, max_height, scoremaps_directory, scoremaps_suffix, jpeg_directory, results_directory, maxmin_min, maxmin_max, maxmin_rad);
function getCrossOffset(src1_basename, src2_basename, kx, ky, scale_prod, nrad, thresh0, sigma, thresh1, min_height, max_height, scoremaps_directory, scoremaps_suffix, jpeg_directory, results_directory, maxmin_min, maxmin_max, maxmin_rad) {
score1_file = src1_basename+scoremaps_suffix+".tiff";
score2_file = src2_basename+scoremaps_suffix+".tiff";
open(scoremaps_directory+"/"+score1_file); // use for derivative
selectImage(score1_file);
// save normalized src1 to be used for mask to disable points far from src1
src1_dup = "src1_dup"; // will have grown, normalized candidates from the first image
run("Duplicate...", "title="+src1_dup);
selectImage(src1_dup); // just in case - duplicate changes selection
run("Subtract...", "value=" + thresh0);
run("Min...", "value=0");
// grow with GB, then re-normalize
run("Gaussian Blur...", "sigma="+sigma); // Maybe different sigma?
run("Differentials ", "operation=[Normalize by local maximum] multiply_d/dx_by="+kx+" multiply_d/dy_by="+ky+" normalization_radius="+nrad);
// put src1_dup aside, continue with score1_file - directional derivative
selectImage(score1_file);
print("operation=[Directional derivative] multiply_d/dx_by="+kx+" multiply_d/dy_by="+ky+" normalization_radius="+nrad);
run("Differentials ", "operation=[Directional derivative] multiply_d/dx_by="+kx+" multiply_d/dy_by="+ky+" normalization_radius="+nrad);
open(scoremaps_directory+"/"+score2_file); // use for derivative
selectImage(score2_file);
src2_dup = "src2_dup";
run("Duplicate...", "title="+src2_dup);
selectImage(score2_file);
run("Subtract...", "value=" + thresh0);
run("Min...", "value=0");
run("Differentials ", "operation=[Normalize by local maximum] multiply_d/dx_by="+kx+" multiply_d/dy_by="+ky+" normalization_radius="+nrad);
imageCalculator("Multiply create", score1_file,score2_file);
img_prod = "Result of "+score1_file;
selectImage(img_prod);
run("Gaussian Blur...", "sigma="+sigma); // max= 0.000541
run("Multiply...", "value="+(-scale_prod));
setMinAndMax(-0.50, 0.50);
img_rslt=src1_basename+"-"+src2_basename+"-GB"+sigma+"-scale"+(scale_prod)+".tiff";
// save as intermediate result
saveAs("Tiff", results_directory + "/"+img_rslt);
print(results_directory + "/"+img_rslt);
grow_gb=0; // 3.0;
grow_gb_thresh=0.8;
// create mask
run("Subtract...", "value="+((min_height+ max_height)/2)); // average
run("Abs");
run("Subtract...", "value="+((max_height-min_height)/2)); // half range
run("Multiply...", "value=-10000.000"); // just a big number and inverse, so good are inside the [min_height,max_height] range
run("Min...", "value=0"); // limit to [0,1] range
run("Max...", "value=1");
// grow it with GB filter
if (grow_gb>0) {
run("Gaussian Blur...", "sigma="+grow_gb);
run("Subtract...", "value="+grow_gb_thresh);
run("Min...", "value=0");
run("Multiply...", "value=10000");
run("Max...", "value=1");
}
// Multiply mask by src1_dup
imageCalculator("Multiply create", img_rslt, src1_dup);
img_mask2 = "Result of "+img_rslt; // combined mask - has src1 maximum, not too high
// measure difference between local maximum and local minimum for the input image2 and mask out to little and too much
jpeg2_file = src2_basename; // +".jpeg" is already included
print ("opening: '"+jpeg_directory+"/"+jpeg2_file+"'");
open(jpeg_directory+"/"+jpeg2_file);
selectImage(jpeg2_file);
run("32-bit");
run("Subtract...", "value=128");
run("Differentials ", "operation=[Local diff] multiply_d/dx_by="+kx+" multiply_d/dy_by="+ky+" normalization_radius="+maxmin_rad);
// save intermediate result
img_minmax2 = src2_basename+"-minmax_diff"+"-r"+maxmin_rad+".tiff";
saveAs("Tiff", results_directory + "/"+img_minmax2);
run("Subtract...", "value="+((maxmin_max+ maxmin_min)/2)); // average
run("Abs");
run("Subtract...", "value="+((maxmin_max-maxmin_min)/2)); // half range
run("Multiply...", "value=-10000.000"); // just a big number and inverse, , so good are inside the [maxmin_min,maxmin_max] range
run("Min...", "value=0"); // limit to [0,1] range
run("Max...", "value=1");
img_minmax2_mask = src2_basename+"-minmax_mask"+"-r"+maxmin_rad+"_"+maxmin_min+"-"+maxmin_max+".tiff";
saveAs("Tiff", results_directory + "/"+img_minmax2_mask);
// combine masks - multiply existing by the new for object contrast
imageCalculator("Multiply create", img_mask2, img_minmax2_mask);
img_mask3 = "Result of "+img_mask2; // combined mask - has src1 maximum, not too high
selectImage(img_mask3);
//
// save mask file
img_mask="mask_"+src1_basename+"-"+src2_basename+"-GB"+sigma+"-scale"+scale_prod+"-min"+min_height+"-max"+max_height+"-grow"+grow_gb+".tiff";
// save as intermediate result
saveAs("Tiff", results_directory + "/"+img_mask);
// create pessimistic scoremap (higher threshold) and multiply by the mask
selectImage(src2_dup);
run("Subtract...", "value=" + thresh1);
run("Min...", "value=0");
run("Multiply...", "value=" + (1.0/(1.0-thresh1))); // will still be much less than 1.0, just expanding [thersh1,1.0] to [0,1]
imageCalculator("Multiply create", src2_dup, img_mask);
img_prod = "Result of "+src2_dup;
selectImage(img_prod);
run("Find Maxima...", "prominence=0.01 output=[Point Selection]");
img_result_score = src2_basename+"-rslt_score.tiff";
//src2_basename
saveAs("Tiff", results_directory + "/"+img_result_score);
/* */
//now open are 9 images
close();
close();
close();
close();
close();
close();
close();
close();
close();
/* */
} // end of function
restoreSettings;
} // end of macro
/*
//#6 - 2180, 2428 0.12
//#7 - 2172, 3350 0.1
//#12 - 2295, 3238 - new? 0.06
//
// 2291, 3241
(-0.05979131273315754, 0.998210899019664)
open("/media/elphel/SSD3-4GB/lwir16-proc/berdich/annotations/collages/pattern-matching/test_macros/L3-1691017285_820540.jpeg-scoremap.tiff");
selectImage("L3-1691017285_820540.jpeg-scoremap.tiff");
run("Subtract...", "value=0.7");
run("Min...", "value=0");
run("Differentials ", "operation=[Normalize by local maximum] multiply=0.000 multiply_0=1.000 normalization=20");
run("Window/Level...");
saveAs("Tiff", "/media/elphel/SSD3-4GB/lwir16-proc/berdich/annotations/collages/pattern-matching/test_macros/L3-1691017285_820540.jpeg-scoremap_lm20.tif");
open("/media/elphel/SSD3-4GB/lwir16-proc/berdich/annotations/collages/pattern-matching/test_macros/L3-1691017285_820540.jpeg-scoremap.tiff");
selectImage("L3-1691017285_820540.jpeg-scoremap.tiff");
selectImage("L3-1691017285_820540.jpeg-scoremap_lm20.tif");
selectImage("L3-1691017285_820540.jpeg-scoremap.tiff");
run("Subtract...", "value=0.500");
run("Min...", "value=0");
run("Differentials ", "operation=[Normalize by local maximum] multiply=0.000 multiply_0=1.000 normalization=20.000");
selectImage("L3-1691017285_820540.jpeg-scoremap_lm20.tif");
selectImage("L3-1691017285_820540.jpeg-scoremap.tiff");
open("/media/elphel/SSD3-4GB/lwir16-proc/berdich/annotations/collages/pattern-matching/test_macros/L3-1691017293_032075.jpeg-scoremap.tiff");
selectImage("L3-1691017293_032075.jpeg-scoremap.tiff");
run("Differentials ", "operation=[Directional derivative] multiply=-0.0598 multiply_0=0.998 normalization=20.000");
selectImage("L3-1691017285_820540.jpeg-scoremap_lm20.tif");
selectImage("Result of L3-1691017293_032075.jpeg-scoremap.tiff");
close();
selectImage("1691017283_609002-RECT-UM10.0_0.97-PIX0.02-CROP-PAL0-RANGE250.0-preview.jpeg");
close();
selectImage("1691017285_262848-RECT-UM10.0_0.97-PIX0.02-CROP-PAL0-RANGE250.0-preview.jpeg");
close();
imageCalculator("Multiply create", "L3-1691017293_032075.jpeg-scoremap.tiff","L3-1691017285_820540.jpeg-scoremap_lm20.tif");
selectImage("Result of L3-1691017293_032075.jpeg-scoremap.tiff");
setMinAndMax(-5.000E-3, 5.000E-3);selectImage("L3-1691017285_820540.jpeg-scoremap_lm20.tif");
selectImage("Result of L3-1691017293_032075.jpeg-scoremap.tiff");
saveAs("Tiff", "/media/elphel/SSD3-4GB/lwir16-proc/berdich/annotations/collages/pattern-matching/test_macros/Result of L3-1691017293_032075.jpeg-scoremap_prod.tif");
run("Gaussian Blur...", "sigma=5");
run("Save");
saveAs("Tiff", "/media/elphel/SSD3-4GB/lwir16-proc/berdich/annotations/collages/pattern-matching/test_macros/Result of L3-1691017293_032075.jpeg-scoremap_prod_gb5.tif");
run("Close All");
*/
macro "fiji_scoremaps" {
saveSettings;
template_dir="/media/elphel/SSD3-4GB/lwir16-proc/berdich/annotations/collages/pattern-matching";
//template_file= "object3_black_half_7-24x24.tiff"; // blurred
template_file="object3_black_48_gb5-0.33_32x32.tiff"; // sharper circle
// template_file="object3_black_48-0.33_32x32.tiff"; // sharp circle
soure_dir="/media/elphel/SSD3-4GB/lwir16-proc/berdich/annotations/collages/pattern-matching/exported_layers_on_grey";
// scoremaps_directory="/media/elphel/SSD3-4GB/lwir16-proc/berdich/annotations/collages/pattern-matching/scoremaps";
scoremaps_directory="/media/elphel/SSD3-4GB/lwir16-proc/berdich/annotations/collages/pattern-matching/scoremaps_medium";
// scoremaps_directory="/media/elphel/SSD3-4GB/lwir16-proc/berdich/annotations/collages/pattern-matching/scoremaps_sharp";
suffix="-scoremap";
create_scoremap("L3-1691017293_032075-7285_82.jpeg", template_file, template_dir, soure_dir, scoremaps_directory, suffix);
create_scoremap("L3-1691017293_032075-7285_82-rot-shift.jpeg", template_file, template_dir, soure_dir, scoremaps_directory, suffix);
create_scoremap("L3-1691017288_801308.jpeg", template_file, template_dir, soure_dir, scoremaps_directory, suffix);
create_scoremap("L3-1691017293_032075.jpeg", template_file, template_dir, soure_dir, scoremaps_directory, suffix);
create_scoremap("L3-1691017286_416693.jpeg", template_file, template_dir, soure_dir, scoremaps_directory, suffix);
create_scoremap("L3-1691017285_820540.jpeg", template_file, template_dir, soure_dir, scoremaps_directory, suffix);
create_scoremap("L3-1691017285_262848.jpeg", template_file, template_dir, soure_dir, scoremaps_directory, suffix);
create_scoremap("L3-1691017284_609002.jpeg", template_file, template_dir, soure_dir, scoremaps_directory, suffix);
create_scoremap("L3-1691017284_070541.jpeg", template_file, template_dir, soure_dir, scoremaps_directory, suffix);
create_scoremap("L3-1691017283_609002.jpeg", template_file, template_dir, soure_dir, scoremaps_directory, suffix);
function create_scoremap (src_file, template, template_dir, src_dir, score_dir, suffix) {
open(template_dir+"/"+template);
selectImage(template);
open(src_dir+"/"+src_file);
selectImage(src_file);
source_width=getWidth();
source_height=getHeight();
run("32-bit");
run("Subtract...", "value=128");
run("Window/Level...");
run("Enhance Contrast", "saturated=0.35");
run("Compute ScoreMap", "template="+template+" image=" + src_file+" method=[Normalised cross-correlation] score_threshold=0.9");
close(); // thresholded result
run("Canvas Size...", "width="+source_width+" height="+source_height+" position=Center zero");
saveAs("Tiff", score_dir + "/"+src_file+suffix+".tiff");
close(); // saved result
close(); // source file
close(); // template file
}
restoreSettings;
}
// /home/elphel/git/imagej-elphel/ij_macros/fiji_scoremaps.txt
macro "fiji_get_points" {
saveSettings;
s = selectionType();
if ( s == -1 ) {
exit("There was no selection.");
} else if( s != 10 ) {
exit("The selection wasn't a point selection.");
} else {
getSelectionCoordinates(xPoints,yPoints);
x = xPoints[0];
y = yPoints[0];
showMessage("Got coordinates ("+x+","+y+")");
showMessage("Got points:" + xPoints.length);
for (i = 0; i < xPoints.length; i++){
print (i, xPoints[i], yPoints[i]);
}
}
/*
2180, 2428 -16: 2164, 2412
3441, 2561
6: 2185, 2431 ( 2180, 2427 - offsest by 5?
7: 2175, 3351
2299, 3241
template_dir="/media/elphel/SSD3-4GB/lwir16-proc/berdich/annotations/collages/pattern-matching";
template_file="object3_black_half_7-24x24.tiff";
soure_dir="/media/elphel/SSD3-4GB/lwir16-proc/berdich/annotations/collages/pattern-matching/exported_layers_on_grey";
scoremaps_directory="/media/elphel/SSD3-4GB/lwir16-proc/berdich/annotations/collages/pattern-matching/scoremaps";
suffix="-scoremap";
create_scoremap("L3-1691017288_801308.jpeg", template_file, template_dir, soure_dir, scoremaps_directory, suffix);
create_scoremap("L3-1691017293_032075.jpeg", template_file, template_dir, soure_dir, scoremaps_directory, suffix);
create_scoremap("L3-1691017286_416693.jpeg", template_file, template_dir, soure_dir, scoremaps_directory, suffix);
create_scoremap("L3-1691017285_820540.jpeg", template_file, template_dir, soure_dir, scoremaps_directory, suffix);
create_scoremap("L3-1691017285_262848.jpeg", template_file, template_dir, soure_dir, scoremaps_directory, suffix);
create_scoremap("L3-1691017284_609002.jpeg", template_file, template_dir, soure_dir, scoremaps_directory, suffix);
create_scoremap("L3-1691017284_070541.jpeg", template_file, template_dir, soure_dir, scoremaps_directory, suffix);
create_scoremap("L3-1691017283_609002.jpeg", template_file, template_dir, soure_dir, scoremaps_directory, suffix);
function create_scoremap (src_file, template, template_dir, src_dir, score_dir, suffix) {
open(template_dir+"/"+template);
selectImage(template);
open(src_dir+"/"+src_file);
selectImage(src_file);
source_width=getWidth();
source_height=getHeight();
run("32-bit");
run("Subtract...", "value=128");
run("Wi8dow/Level...");
run("Enhance Contrast", "saturated=0.35");
run("Compute ScoreMap", "template="+template+" image=" + src_file+" method=[Normalised cross-correlation] score_threshold=0.9");
close(); // thresholded result
run("Canvas Size...", "width="+source_width+" height="+source_height+" position=Center zero");
saveAs("Tiff", score_dir + "/"+src_file+suffix+".tiff");
close(); // saved result
close(); // source file
close(); // template file
}
*/
restoreSettings;
}
// /home/elphel/git/imagej-elphel/ij_macros/fiji_scoremaps.txt
macro "goto_coordinates" {
saveSettings;
width=300;
height=200;
xc=0; yc=0;
Dialog.create("My dialog"); // ("Go to selected coordinates. Creates rectangular selection" );
Dialog.addNumber("Selection center X",xc);
Dialog.addNumber("Selection center Y",yc);
Dialog.addNumber("Selection width", width);
Dialog.addNumber("Selection height", height);
Dialog.show();
xc = Dialog.getNumber();
yc = Dialog.getNumber();
width = Dialog.getNumber();
height = Dialog.getNumber();
print("xc="+xc+", yc="+yc+", width="+width+", height="+height);
makeRectangle(xc-width/2, yc-height/2, width, height);
run("To Selection");
restoreSettings;
}
macro "make_snapshots" {
saveSettings;
// copy lines to match required objects and put actual coordinates/names
// (no spaces) below using kate's <cntrl><shift>b mode
// To run - open file in imagej, go to Plugins->Macros->Run and select this file (should have .txt extension)
//
subdir = "objects"
Dialog.create("objects snapshots "); // ("Go to selected coordinates. Creates rectangular selection" );
Dialog.addString("Subdirectory name",subdir);
Dialog.show();
subdir = Dialog.getString();
makeSnapshot( 2456, 6458 , 150, 150, "_M", subdir);
makeSnapshot( 4790, 9484 , 150, 150, "01", subdir);
makeSnapshot( 4624, 10291, 150, 150, "02", subdir);
makeSnapshot( 4642, 12968, 150, 150, "03", subdir);
makeSnapshot( 4734, 11946, 150, 150, "04", subdir);
makeSnapshot( 5266, 11618, 150, 150, "05", subdir);
makeSnapshot( 4865, 5362 , 150, 150, "06", subdir);
makeSnapshot( 4805, 7027 , 150, 150, "07", subdir);
makeSnapshot( 4791, 8698 , 150, 150, "08", subdir);
makeSnapshot( 4358, 5972 , 150, 150, "09", subdir);
makeSnapshot( 4785, 12213, 150, 150, "10", subdir);
makeSnapshot( 5620, 11280, 150, 150, "11", subdir);
function makeSnapshot(xc, yc, width, height, suffix, subdir) {
base_directory=getInfo("image.directory");
directory = base_directory+"/"+subdir;
filename=getInfo("image.filename")+"-"+suffix;
makeRectangle(xc-width/2, yc-height/2, width, height);
run("Duplicate...", " ");
print("saving object snapshot to: "+ directory+"/"+filename+"-"+xc+"_"+yc+"_"+width+"_"+height+".tiff");
File.makeDirectory(directory);
saveAs("Tiff", directory+"/"+filename+"-"+xc+"_"+yc+"_"+width+"_"+height+".tiff");
saveAs("Jpeg", directory+"/"+filename+"-"+xc+"_"+yc+"_"+width+"_"+height+".jpeg");
close();
}
restoreSettings;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment