Commit 5f08ad84 authored by Andrey Filippov's avatar Andrey Filippov
Browse files

Update ij macros

parent 849b916d
Loading
Loading
Loading
Loading
+54 −9
Original line number Original line Diff line number Diff line
@@ -18,21 +18,25 @@ macro "cross_offset" {
  thresh1 =     0.7;
  thresh1 =     0.7;
  sigma =       10.0;
  sigma =       10.0;
  min_height= -0.1;
  min_height= -0.1;
  max_height=  0.25;
  max_height=  0.18; // 0.25;
  maxmin_min = 82.0; //difference between local maximum and local minimum (norm_radius) should be not less than this
  maxmin_min = 75;  // 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_max = 150; //difference between local maximum and local minimum (norm_radius) should be not more than this
  maxmin_rad = 15.0
  maxmin_rad = 15.0
  // for illustrations - run for one pair with disabled close() in the end
  // 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
  // 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
  //>>> dx,dy (-59, 985) pixels, l = 987 pixels = 19.7m


  File.makeDirectory(results_directory);   
  // negative disparity
  // 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-1691017293_032075-7285_82.jpeg", "L3-1691017285_820540.jpeg", -0.060, 0.998, 150, 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);
  getCrossOffset("L3-1691017285_820540.jpeg","L3-1691017293_032075-7285_82.jpeg",  0.060, -0.998, 150, 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) {
  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) {
    nrad_dd = 10; // normalization for directional derivative
    min_dd = 0.3; // do not boost dd if scoremap less than this
    score1_file = src1_basename+scoremaps_suffix+".tiff";
    score1_file = src1_basename+scoremaps_suffix+".tiff";
    score2_file = src2_basename+scoremaps_suffix+".tiff";
    score2_file = src2_basename+scoremaps_suffix+".tiff";
    open(scoremaps_directory+"/"+score1_file); // use for derivative
    open(scoremaps_directory+"/"+score1_file); // use for derivative
@@ -50,8 +54,28 @@ macro "cross_offset" {
    
    
    // put src1_dup aside, continue with score1_file - directional derivative
    // put src1_dup aside, continue with score1_file - directional derivative
    selectImage(score1_file);
    selectImage(score1_file);
    src1_dd = src1_basename+"-directional_derivative.tiff";
    run("Duplicate...", "title="+src1_dd);
    selectImage(src1_dd);
    print("operation=[Directional derivative] multiply_d/dx_by="+kx+" multiply_d/dy_by="+ky+" normalization_radius="+nrad);
    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);
    run("Differentials ", "operation=[Directional derivative] multiply_d/dx_by="+kx+" multiply_d/dy_by="+ky+" normalization_radius="+nrad);
    saveAs("Tiff", results_directory + "/"+src1_dd);  
    src1_dd = src1_basename+"-directional_derivative_normalized.tiff";
    rename(src1_dd);
    // normalize directional derivative by the limited by min local maximum of the scoremap
    selectImage(score1_file); // original scoremap
    src1_dd_norm = "src1_dd_norm"; // no need to save
    run("Duplicate...", "title="+src1_dd_norm);
    selectImage(src1_dd_norm);
    run("Differentials ", "operation=[Local max] multiply_d/dx_by="+kx+" multiply_d/dy_by="+ky+" normalization_radius="+nrad_dd);
    run("Min...", "value="+min_dd);
    imageCalculator("Divide", src1_dd, src1_dd_norm);
    saveAs("Tiff", results_directory + "/"+src1_dd);  // now src1_dd is normalized directiona derivative 
    
//run("Window/Level...");
//setMinAndMax(-0.50, 0.50);
    selectImage(src1_dd_norm);
    close(); // src1_dd_norm is not needed anymore
    open(scoremaps_directory+"/"+score2_file); // use for derivative
    open(scoremaps_directory+"/"+score2_file); // use for derivative
    selectImage(score2_file);
    selectImage(score2_file);
    src2_dup = "src2_dup";
    src2_dup = "src2_dup";
@@ -61,13 +85,30 @@ macro "cross_offset" {
    run("Min...", "value=0");
    run("Min...", "value=0");
    run("Differentials ", "operation=[Normalize by local maximum] multiply_d/dx_by="+kx+" multiply_d/dy_by="+ky+" normalization_radius="+nrad);
    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);
    // save normalized score2 as intermediate result
    img_prod = "Result of "+score1_file;
    score2_norm_file = src2_basename+scoremaps_suffix+"-norm.tiff";
    rename(score2_norm_file);
    saveAs("Tiff", results_directory + "/"+score2_norm_file);  
    
    // create same-size sampling, not just same max value
    run("Differentials ", "operation=[Local ismax] multiply_d/dx_by="+kx+" multiply_d/dy_by="+ky+" normalization_radius="+nrad);
    run("Gaussian Blur...", "sigma=2.0");
    run("Differentials ", "operation=[Normalize by local maximum] multiply_d/dx_by="+kx+" multiply_d/dy_by="+ky+" normalization_radius="+nrad);
    score2_normsize_file = src2_basename+scoremaps_suffix+"-normsize.tiff";
    rename(score2_normsize_file);
    saveAs("Tiff", results_directory + "/"+score2_normsize_file);  
    
    imageCalculator("Multiply create", src1_dd,score2_normsize_file); // score1_file was directional derivative, now src1_dd
    img_prod = "Result of "+src1_dd;
    selectImage(img_prod); 
    selectImage(img_prod); 
    run("Gaussian Blur...", "sigma="+sigma); // max= 0.000541
    run("Gaussian Blur...", "sigma="+sigma); // max= 0.000541
    run("Multiply...", "value="+(-scale_prod));
    run("Multiply...", "value="+(-scale_prod));
    setMinAndMax(-0.50, 0.50);
    setMinAndMax(-0.50, 0.50);
    img_rslt=src1_basename+"-"+src2_basename+"-GB"+sigma+"-scale"+(scale_prod)+".tiff";
    img_rslt=src1_basename+"-"+src2_basename+"-GB"+sigma+"-scale"+(scale_prod)+".tiff";
// 2180, 2429    0.2046-> 0.1269 0.2227??     old: 0.1183  -> 0.2136 (-0.02405 / 0.7425)  -0.03189 + -> 0.2832 (0.1123) 120/300 -> .0113 150/300 -> .14
// 2172 3350     0.1131->0.09811 * 1.2 0.1134 old: 0.09811 -> 0.1131 (-0.01059 / 0.7407)  -0.01423 + -> 0.1524                  -> .061  150/300 -> .076
// 131.44, 250.05
// 2008 3164 0.008551 -> 0.2039                                      (-0.01463 / 0.03470) -0.02909 -0.01443->0.0290-9 ->0.4082  -> 0.2014
// save as intermediate result  
// save as intermediate result  
    saveAs("Tiff", results_directory + "/"+img_rslt);
    saveAs("Tiff", results_directory + "/"+img_rslt);
    print(results_directory + "/"+img_rslt);
    print(results_directory + "/"+img_rslt);
@@ -88,6 +129,9 @@ macro "cross_offset" {
        run("Multiply...", "value=10000");
        run("Multiply...", "value=10000");
        run("Max...", "value=1");
        run("Max...", "value=1");
    }
    }
   img_rslt=src1_basename+"-"+src2_basename+"-GB"+sigma+"-scale"+(scale_prod)+"-height-mask.tiff";
   rename(img_rslt); 
   saveAs("Tiff", results_directory + "/"+img_rslt); // now it is height mask
// Multiply mask by src1_dup
// Multiply mask by src1_dup
   imageCalculator("Multiply create", img_rslt, src1_dup);
   imageCalculator("Multiply create", img_rslt, src1_dup);
   img_mask2 = "Result of "+img_rslt; // combined mask - has src1 maximum, not too high
   img_mask2 = "Result of "+img_rslt; // combined mask - has src1 maximum, not too high
@@ -132,7 +176,8 @@ macro "cross_offset" {
//src2_basename    
//src2_basename    
    saveAs("Tiff", results_directory + "/"+img_result_score);
    saveAs("Tiff", results_directory + "/"+img_result_score);
/* */
/* */
//now open are 9 images
//now open are 10 images
    close();
    close();
    close();
    close();
    close();
    close();
    close();
+5 −3
Original line number Original line Diff line number Diff line
@@ -2,15 +2,17 @@ macro "fiji_scoremaps" {
  saveSettings;
  saveSettings;
  template_dir="/media/elphel/SSD3-4GB/lwir16-proc/berdich/annotations/collages/pattern-matching";
  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_half_7-24x24.tiff"; // blurred
  template_file="object3_black_48_gb5-0.33_32x32.tiff"; // sharper circle
//  template_file="object3_black_48_gb5-0.33_32x32.tiff"; // sharper circle
// template_file="object3_black_48-0.33_32x32.tiff"; // sharp circle
// template_file="object3_black_48-0.33_32x32.tiff"; // sharp circle
  template_file="object4_black_48_gb8-0.333-UM5-0.9-48x48.tiff"; // with unsharp mask
  
  
  soure_dir="/media/elphel/SSD3-4GB/lwir16-proc/berdich/annotations/collages/pattern-matching/exported_layers_on_grey";
  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";
  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_medium";
//  scoremaps_directory="/media/elphel/SSD3-4GB/lwir16-proc/berdich/annotations/collages/pattern-matching/scoremaps_sharp";
//  scoremaps_directory="/media/elphel/SSD3-4GB/lwir16-proc/berdich/annotations/collages/pattern-matching/scoremaps_sharp";
   scoremaps_directory="/media/elphel/SSD3-4GB/lwir16-proc/berdich/annotations/collages/pattern-matching/scoremaps_UM5-0.9
  suffix="-scoremap";
  suffix="-scoremap";
  
  File.makeDirectory(scoremaps_directory); 


  create_scoremap("L3-1691017293_032075-7285_82.jpeg", template_file, template_dir, soure_dir, scoremaps_directory, suffix);
  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-1691017293_032075-7285_82-rot-shift.jpeg", template_file, template_dir, soure_dir, scoremaps_directory, suffix);