import ij.IJ; import ij.Prefs; import ij.gui.GenericDialog; import ij.gui.NonBlockingGenericDialog; import ij.gui.Plot; import ij.gui.Roi; import ij.gui.TextRoi; import ij.gui.WaitForUserDialog; import ij.ImagePlus; import ij.ImageStack; import ij.measure.Calibration; import ij.measure.Measurements; import ij.measure.ResultsTable; import ij.plugin.Colors; import ij.plugin.Concatenator; import ij.plugin.Duplicator; import ij.plugin.filter.Analyzer; import ij.plugin.frame.RoiManager; import ij.plugin.frame.ThresholdAdjuster; import ij.plugin.HyperStackConverter; import ij.plugin.ImageCalculator; import ij.plugin.PlugIn; import ij.plugin.StackEditor; import ij.plugin.SubstackMaker; import ij.plugin.SubHyperstackMaker; import ij.plugin.ZProjector; import ij.process.Blitter; import ij.process.ImageConverter; import ij.process.ImageProcessor; import ij.process.ImageStatistics; import ij.text.TextPanel; import ij.text.TextWindow; import ij.util.Tools; import ij.WindowManager; import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import java.awt.Image; import java.awt.Rectangle; import java.awt.Toolkit; import java.awt.Window; import java.awt.geom.Rectangle2D; import java.io.BufferedOutputStream; import java.io.BufferedWriter; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.net.URL; import java.text.DecimalFormat; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Arrays; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.TimeZone; import org.apache.commons.math3.linear.MatrixUtils; import org.apache.commons.math3.linear.RealMatrix; import org.apache.commons.math3.linear.SingularValueDecomposition; /** JEasyTFM version 2.1 JEasyTFM is an open-source ImageJ plugins package aimed for the automatic analysis of large Traction Force Microscopy kinetic images data. This package able the automatic analysis of TFM data in time lapse with: - 1 to 2 beads channels (i.e. with two different beads colors) - 1 to 3 cells channels (for example with Bright Field, GFP and Hoechst channels) - multi-positions (i.e. several sample positions within a given experiment) - calculation of the traction forces - automatic cells segmentation carried out from their BF images - integration of the forces over the cells - tracking of the beads - focal adhesion segmentations - calculation of the traction forces applied on the focal adhesions - batch-processing using jobs creation, launching and tracking This plugin generates the "JEasyTFM.txt". i.e. the configuration file needed to launch traction force analysis methods. Author: Philippe Carl (Philippe DOT Carl AT unistra DOT fr) Requires: ImageJ 1.53d47 or later History: 2020/07/31: Version 1.0 - First released version: The analysis package is made available for the community. 2023/01/23: Version 2.0 - Extension of the code to allow the calculation of the traction forces applied on the focal adhesions. 2023/02/23: Version 2.1 - For the particle_tracker feature JEasyTFM uses now the 1.0.25 version of the MosaicSuite code released on 20 September 2022 (instead of the 1.5. version of the Particle_Tracker code released September 2006) **/ /** Copyright (C) 2020 Philippe Carl. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. **/ public class launch_job implements PlugIn { int unitIndex = 0; // index corresponding to the force calculated in pN int FTTC_max_vector_length = 24; // 24 int vs3 = 16; // PIV window size double length_scale; // = 6.5 / 60.0; // 6.5µm is the size of the Hamamatsu ORCA-Flash4.0 V2 cell size (https://www.hamamatsu.com/resources/pdf/sys/SCAS0081E_C11440-22CU.pdf) and 60 corresponds to an 60x objective magnification double window_area; // = Math.pow(vs3 * length_scale, 2); String length_unit = "micron"; String lut = "multitxt"; String config_file; boolean underscrore = true; boolean error = false; String link = underscrore ? "_-_" : " - "; boolean dupli, debug; String folder , file1 , file2; int objective_magnification, job_index, channels, slices, frames, frames_begin, cells_number, beads, ch, numberCh, image_chosen, E; // double camera_pixel_size, precisionForLambda, lambda; double camera_pixel_size, precisionForLambda; double [] lambda_values = null; boolean beads1, beads2; boolean ch1, ch2, ch3; boolean mod1, mod2, mod3; int [] format = { 0x1, 0x2, 0x4, 0x10, 0x20, 0x40 }; boolean cells_images , beads_reference_images , beads_sequence_images , traction_force , cells_analysis , traction_high_force , FA_segmentation , traction_force_applied_on_FA; boolean beads_reference_images_find_focused_slices , beads_sequence_images_find_focused_slices , traction_high_enhance_constrast; int cells_starting_folder, cells_ending_folder, beads_reference_starting_folder, beads_reference_ending_folder, beads_sequence_starting_folder, beads_sequence_ending_folder, traction_starting_folder, traction_ending_folder, cells_analysis_starting_folder, cells_analysis_ending_folder, traction_high_starting_folder, traction_high_ending_folder, FA_segmentation_starting_folder, FA_segmentation_ending_folder, traction_applied_on_FA_starting_folder, traction_applied_on_FA_ending_folder; boolean traction_force_alignment, traction_force_alignment_make, traction_force_alignment_crop, traction_force_calculation, piv_calculation, lambda_calculation, force_calculation, force_superposition; boolean high_piv_calculation, particle_tracker; boolean cells_segmentation, cells_selection, force_integration; int val; File file; // ResultsTable rt; String str; int counter, col; double value; long startTime; long stopTime; long elapsedTime; // SimpleDateFormat sdf = new SimpleDateFormat("MMM dd,yyyy HH:mm"); SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS"); Date resultdate; URL url; Image icon = null; public void run(String arg) { try { url = getClass().getResource("/image/JEasyTFM.ico"); icon = Toolkit.getDefaultToolkit().getImage(url); } catch (Exception e) { IJ.showMessage("Loading the icon image", "The icon image \"/image/JEasyTFM.ico\" could not be found!"); } sdf .setTimeZone(TimeZone.getTimeZone("UTC")); startTime = System.currentTimeMillis(); config_file = IJ.getDirectory("plugins") + "JEasyTFM.txt"; setData ( readData(config_file) ); if(!saveBeginJob()) return; showData(); if( cells_images ) cells_images (); if( beads_reference_images ) beads_reference_images (); if( beads_sequence_images ) beads_sequence_images (); if( traction_force ) traction_force (); if( cells_analysis ) cells_analysis (); if( traction_high_force ) traction_high_force (); if( FA_segmentation ) FA_segmentation (); if( traction_force_applied_on_FA ) traction_force_applied_on_FA (); stopTime = System.currentTimeMillis(); elapsedTime = stopTime - startTime; resultdate = new Date(elapsedTime); showDialogWithCustomOkAndNoCancel("Traction Force Microscopy Analysis", "The analysis took " + sdf.format(resultdate), "The analysis has been completed!!!"); } private String [] readData(String parameters_file) { String [] data = {"false"}; String [] columns; file = new File(parameters_file); if (!file.exists()) IJ.log("File not found"); try { String config = IJ.openAsString(parameters_file); String [] lines = Tools.split(config ,"\n"); data = new String[lines.length]; for(int i = 0; i != lines.length; i++) { columns = Tools.split(lines[i],"\t"); data[i] = columns[1]; } } catch (Exception e) { IJ.log("File open error \n\"" + e.getMessage() + "\"\n"); } return data; } private void setData(String [] str_config_data) { int i; if(str_config_data.length == 56) { i = 0; camera_pixel_size = Double.valueOf ( str_config_data[i++] ); objective_magnification = Integer.parseInt ( str_config_data[i++] ); debug = Boolean.parseBoolean ( str_config_data[i++] ); folder = str_config_data[i++] ; file1 = str_config_data[i++] ; file2 = str_config_data[i++] ; cells_number = Integer.parseInt ( str_config_data[i++] ); slices = Integer.parseInt ( str_config_data[i++] ); frames = Integer.parseInt ( str_config_data[i++] ); frames_begin = Integer.parseInt ( str_config_data[i++] ); beads = Integer.parseInt ( str_config_data[i++] ); ch = Integer.parseInt ( str_config_data[i++] ); numberCh = Integer.parseInt ( str_config_data[i++] ); E = Integer.parseInt ( str_config_data[i++].trim() ); precisionForLambda = Double.valueOf ( str_config_data[i++] ); cells_images = Boolean.parseBoolean ( str_config_data[i++] ); image_chosen = Integer.parseInt ( str_config_data[i++] ); cells_starting_folder = Integer.parseInt ( str_config_data[i++] ); cells_ending_folder = Integer.parseInt ( str_config_data[i++] ); beads_reference_images = Boolean.parseBoolean ( str_config_data[i++] ); beads_reference_images_find_focused_slices = Boolean.parseBoolean ( str_config_data[i++] ); beads_reference_starting_folder = Integer.parseInt ( str_config_data[i++] ); beads_reference_ending_folder = Integer.parseInt ( str_config_data[i++] ); beads_sequence_images = Boolean.parseBoolean ( str_config_data[i++] ); beads_sequence_images_find_focused_slices = Boolean.parseBoolean ( str_config_data[i++] ); beads_sequence_starting_folder = Integer.parseInt ( str_config_data[i++] ); beads_sequence_ending_folder = Integer.parseInt ( str_config_data[i++] ); traction_force = Boolean.parseBoolean ( str_config_data[i++] ); traction_starting_folder = Integer.parseInt ( str_config_data[i++] ); traction_ending_folder = Integer.parseInt ( str_config_data[i++] ); traction_force_alignment = Boolean.parseBoolean ( str_config_data[i++] ); traction_force_alignment_make = Boolean.parseBoolean ( str_config_data[i++] ); traction_force_alignment_crop = Boolean.parseBoolean ( str_config_data[i++] ); traction_force_calculation = Boolean.parseBoolean ( str_config_data[i++] ); piv_calculation = Boolean.parseBoolean ( str_config_data[i++] ); lambda_calculation = Boolean.parseBoolean ( str_config_data[i++] ); force_calculation = Boolean.parseBoolean ( str_config_data[i++] ); force_superposition = Boolean.parseBoolean ( str_config_data[i++] ); // force_superposition = Boolean.parseBoolean ( str_config_data[i++] ) != 0; cells_analysis = Boolean.parseBoolean ( str_config_data[i++] ); cells_analysis_starting_folder = Integer.parseInt ( str_config_data[i++] ); cells_analysis_ending_folder = Integer.parseInt ( str_config_data[i++] ); cells_segmentation = Boolean.parseBoolean ( str_config_data[i++] ); cells_selection = Boolean.parseBoolean ( str_config_data[i++] ); force_integration = Boolean.parseBoolean ( str_config_data[i++] ); traction_high_force = Boolean.parseBoolean ( str_config_data[i++] ); traction_high_enhance_constrast = Boolean.parseBoolean ( str_config_data[i++] ); traction_high_starting_folder = Integer.parseInt ( str_config_data[i++] ); traction_high_ending_folder = Integer.parseInt ( str_config_data[i++] ); high_piv_calculation = Boolean.parseBoolean ( str_config_data[i++] ); particle_tracker = Boolean.parseBoolean ( str_config_data[i++] ); FA_segmentation = Boolean.parseBoolean ( str_config_data[i++] ); FA_segmentation_starting_folder = Integer.parseInt ( str_config_data[i++] ); FA_segmentation_ending_folder = Integer.parseInt ( str_config_data[i++] ); traction_force_applied_on_FA = Boolean.parseBoolean ( str_config_data[i++] ); traction_applied_on_FA_starting_folder = Integer.parseInt ( str_config_data[i++] ); traction_applied_on_FA_ending_folder = Integer.parseInt ( str_config_data[i++] ); length_scale = camera_pixel_size / objective_magnification; window_area = Math.pow(vs3 * length_scale, 2); beads1 = (beads & 0x1 ) != 0; beads2 = (beads & 0x2 ) != 0; ch1 = (ch & 0x1 ) != 0; ch2 = (ch & 0x2 ) != 0; ch3 = (ch & 0x4 ) != 0; mod1 = (ch & 0x10) != 0; mod2 = (ch & 0x20) != 0; mod3 = (ch & 0x40) != 0; } else { IJ.log("The configuration file is empty"); return; } } private boolean saveBeginJob() { if (!checkAndCreateFolder(folder + "Jobs")) return false; job_index = 0; dupli = true; while (dupli) { job_index++; // file = new File(folder + "Jobs" + File.separator + "job_" + IJ.pad(job_index, 2) + "_begin.txt"); file = new File(folder + "Jobs" + File.separator + "JEasyTFM_" + job_index + "_begin.txt"); dupli = file.exists(); } saveJob(folder + "Jobs" + File.separator + "JEasyTFM_" + job_index + "_begin.txt"); return true; } private void saveJob(String path) { beads = beads1 ? 0x1 : 0; beads = beads2 ? beads + 0x2 : beads; ch = ch1 ? 0x1 : 0; ch = ch2 ? ch + 0x2 : ch; ch = ch3 ? ch + 0x4 : ch; ch = mod1 ? ch + 0x10 : ch; ch = mod2 ? ch + 0x20 : ch; ch = mod3 ? ch + 0x40 : ch; try { FileOutputStream fos = new FileOutputStream (path); BufferedOutputStream bos = new BufferedOutputStream (fos); PrintWriter writer = new PrintWriter (bos); writer.println("camera_pixel_size\t" + camera_pixel_size); writer.println("objective_magnification\t" + objective_magnification); writer.println("debug\t" + debug); writer.println("folder\t" + folder); writer.println("file1\t" + file1); writer.println("file2\t" + file2); writer.println("cells_number\t" + cells_number); writer.println("slices\t" + slices); writer.println("frames\t" + frames); writer.println("frames_begin\t" + frames_begin); writer.println("beads\t" + beads); writer.println("channel\t" + ch); writer.println("number of acquired channels\t" + numberCh); writer.println("Young's_modulus_(in_Pascal)\t" + E); writer.println("precision for regularization_factor\t" + precisionForLambda); writer.println("cells_images\t" + cells_images); writer.println("image_chosen\t" + image_chosen); writer.println("cells_starting_folder\t" + cells_starting_folder); writer.println("cells_ending_folder\t" + cells_ending_folder); writer.println("beads_reference_images\t" + beads_reference_images); writer.println("beads_reference_images_find_focused_slices\t" + beads_reference_images_find_focused_slices); writer.println("beads_reference_starting_folder\t" + beads_reference_starting_folder); writer.println("beads_reference_ending_folder\t" + beads_reference_ending_folder); writer.println("beads_sequence_images\t" + beads_sequence_images); writer.println("beads_sequence_images_find_focused_slices\t" + beads_sequence_images_find_focused_slices); writer.println("beads_sequence_starting_folder\t" + beads_sequence_starting_folder); writer.println("beads_sequence_ending_folder\t" + beads_sequence_ending_folder); writer.println("traction_force\t" + traction_force); writer.println("traction_starting_folder\t" + traction_starting_folder); writer.println("traction_ending_folder\t" + traction_ending_folder); writer.println("traction_force_alignment\t" + traction_force_alignment); writer.println("traction_force_alignment_make\t" + traction_force_alignment_make); writer.println("traction_force_alignment_crop\t" + traction_force_alignment_crop); writer.println("traction_force_calculation\t" + traction_force_calculation); writer.println("piv_calculation\t" + piv_calculation); writer.println("lambda_calculation\t" + lambda_calculation); writer.println("force_calculation\t" + force_calculation); writer.println("force_superposition\t" + force_superposition); writer.println("cells_analysis\t" + cells_analysis); writer.println("cells_analysis_starting_folder\t" + cells_analysis_starting_folder); writer.println("cells_analysis_ending_folder\t" + cells_analysis_ending_folder); writer.println("cells_segmentation\t" + cells_segmentation); writer.println("cells_selection\t" + cells_selection); writer.println("force_integration\t" + force_integration); writer.println("traction_high_force\t" + traction_high_force); writer.println("traction_high_enhance_constrast\t" + traction_high_enhance_constrast); writer.println("traction_high_starting_folder\t" + traction_high_starting_folder); writer.println("traction_high_ending_folder\t" + traction_high_ending_folder); writer.println("high_piv_calculation\t" + high_piv_calculation); writer.println("particle_tracker\t" + particle_tracker); writer.println("FA_segmentation\t" + FA_segmentation); writer.println("FA_segmentation_starting_folder\t" + FA_segmentation_starting_folder); writer.println("FA_segmentation_ending_folder\t" + FA_segmentation_ending_folder); writer.println("traction_force_applied_on_FA\t" + traction_force_applied_on_FA); writer.println("traction_applied_on_FA_starting_folder\t" + traction_applied_on_FA_starting_folder); writer.println("traction_applied_on_FA_ending_folder\t" + traction_applied_on_FA_ending_folder); writer.close(); } catch (IOException e) { showDialogWithImageAndCustomOkAndNoCancel("Job saving", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + path, "The job file couldn't be saved"); } } private void showData() { String title; Window window; TextWindow tw; TextPanel tp; title = "Analysis settings"; window = WindowManager.getWindow(title); if (!(window instanceof TextWindow)) { IJ.run ("New... ", "name=[" + title + "] type=Table"); window = WindowManager.getWindow(title); window .setIconImage(icon); } tw = (TextWindow) window; tw .setSize (900, 1000); tw .setLocation( 10, 10); tp = tw.getTextPanel(); tp.clear (); tp.setColumnHeadings ("Parameter\tValue"); tp.appendLine ("Folder\t" + folder); tp.appendLine ("File1\t" + file1); tp.appendLine ("File2\t" + file2); tp.appendLine ("Slices\t" + slices); tp.appendLine ("Frames\t" + frames); tp.appendLine ("Frames_begin\t" + frames_begin); tp.appendLine ("Beads_color_1\t" + beads1); tp.appendLine ("Beads_color_2\t" + beads2); tp.appendLine ("Ch1\t" + ch1); tp.appendLine ("Ch2\t" + ch2); tp.appendLine ("Ch3\t" + ch3); tp.appendLine ("Model1\t" + mod1); tp.appendLine ("Model2\t" + mod2); tp.appendLine ("Model3\t" + mod3); tp.appendLine ("Number of acquired channels\t" + numberCh); tp.appendLine ("Young's_modulus_(in_Pascal)\t" + E); tp.appendLine ("Precision_for_regularization_factor\t" + precisionForLambda); tp.appendLine ("Cells_images\t" + cells_images); tp.appendLine ("Image_chosen\t" + image_chosen); tp.appendLine ("Cells_starting_folder\t" + cells_starting_folder); tp.appendLine ("Cells_ending_folder\t" + cells_ending_folder); tp.appendLine ("Beads_reference_images\t" + beads_reference_images); tp.appendLine ("Beads_reference_images_find_focused_slices\t" + beads_reference_images_find_focused_slices); tp.appendLine ("Beads_reference_starting_folder\t" + beads_reference_starting_folder); tp.appendLine ("Beads_reference_ending_folder\t" + beads_reference_ending_folder); tp.appendLine ("Beads_sequence_images\t" + beads_sequence_images); tp.appendLine ("Beads_sequence_images_find_focused_slices\t" + beads_sequence_images_find_focused_slices); tp.appendLine ("Beads_sequence_starting_folder\t" + beads_sequence_starting_folder); tp.appendLine ("Beads_sequence_ending_folder\t" + beads_sequence_ending_folder); tp.appendLine ("Traction_force\t" + traction_force); tp.appendLine ("Traction_starting_folder\t" + traction_starting_folder); tp.appendLine ("Traction_ending_folder\t" + traction_ending_folder); tp.appendLine ("Traction_force_alignment\t" + traction_force_alignment); tp.appendLine ("Traction_force_alignment_make\t" + traction_force_alignment_make); tp.appendLine ("Traction_force_alignment_crop\t" + traction_force_alignment_crop); tp.appendLine ("Traction_force_calculation\t" + traction_force_calculation); tp.appendLine ("PIV_calculation\t" + piv_calculation); tp.appendLine ("Lambda_calculation\t" + lambda_calculation); tp.appendLine ("Force_calculation\t" + force_calculation); tp.appendLine ("Force_superposition\t" + force_superposition); tp.appendLine ("Cells_analysis\t" + cells_analysis); tp.appendLine ("Cells_analysis_starting_folder\t" + cells_analysis_starting_folder); tp.appendLine ("Cells_analysis_ending_folder\t" + cells_analysis_ending_folder); tp.appendLine ("Cells_segmentation\t" + cells_segmentation); tp.appendLine ("Cells_selection\t" + cells_selection); tp.appendLine ("Force_integration\t" + force_integration); tp.appendLine ("Traction_high_force\t" + traction_high_force); tp.appendLine ("Traction_high_enhance_constrast\t" + traction_high_enhance_constrast); tp.appendLine ("Traction_high_starting_folder\t" + traction_high_starting_folder); tp.appendLine ("Traction_high_ending_folder \t" + traction_high_ending_folder); tp.appendLine ("High_piv_calculation\t" + high_piv_calculation); tp.appendLine ("Particle_tracker\t" + particle_tracker); tp.appendLine ("FA_segmentation\t" + FA_segmentation); tp.appendLine ("FA_segmentation_starting_folder\t" + FA_segmentation_starting_folder); tp.appendLine ("FA_segmentation_ending_folder\t" + FA_segmentation_ending_folder); tp.appendLine ("traction_force_applied_on_FA\t" + traction_force_applied_on_FA); tp.appendLine ("traction_applied_on_FA_starting_folder\t" + traction_applied_on_FA_starting_folder); tp.appendLine ("traction_applied_on_FA_ending_folder\t" + traction_applied_on_FA_ending_folder); } private void cells_images() { ImagePlus imp, imp2, impout; int cells_folder, channel, frame; int [] bestFocus; String folder_begin, folder_cell; for(channel = 1; channel <= numberCh && channel != 0; channel++) { // if(ch == 0) channel = 0; if((ch & 0x1) == 0 && (ch & 0x2) == 0 && (ch & 0x4) == 0) channel = 0; else if((ch & format[channel - 1]) == 0) continue; for(cells_folder = cells_starting_folder; cells_folder <= cells_ending_folder; cells_folder++) { folder_cell = folder + "Cell " + cells_folder + File.separator; checkAndCreateFolder(folder_cell); imp = imp2 = null; if(frames == 1) { if(debug) { if(channel == 0) imp = checkScale (folder + file1 + cells_folder + "_" + IJ.pad((numberCh + 1) * cells_folder - 1 , 2) + ".tif"); else imp = checkScale (folder + file1 + cells_folder + "_" + IJ.pad((numberCh + 1) * (cells_folder - 1) + channel, 2) + ".tif"); // imp = checkScale (folder + file1 + cells_folder + "_" + IJ.pad(3 * cells_folder - 1, 2) + ".tif"); // ch2 // imp = checkScale (folder + file1 + cells_folder + "_" + IJ.pad(3 * cells_folder - 2, 2) + ".tif"); // ch1 // imp = IJ.openImage(folder + file1 + cells_folder + "_" + IJ.pad(3 * cells_folder - 1, 2) + ".tif"); // imp = IJ.openImage(folder + file1 + cells_folder + "_" + IJ.pad(3 * cells_folder - 2, 2) + ".tif"); // imp.show(); } else { if(channel == 0) imp = openStealth (folder + file1 + cells_folder + "_" + IJ.pad((numberCh + 1) * cells_folder - 1 , 2) + ".tif"); else imp = openStealth (folder + file1 + cells_folder + "_" + IJ.pad((numberCh + 1) * (cells_folder - 1) + channel, 2) + ".tif"); // imp.show(); } if(imp == null) { if(!error) { error = true; if(channel == 0) showDialogWithImageAndCustomOkAndNoCancel("Cells images", "undo.png", "The following file:\n\t\n" + folder + file1 + cells_folder + "_" + IJ.pad(3 * cells_folder - 1 , 2) + ".tif\n\t\ncould not be found", "The analysis is stopped at the step \"Cells images\""); else showDialogWithImageAndCustomOkAndNoCancel("Cells images", "undo.png", "The following file:\n\t\n" + folder + file1 + cells_folder + "_" + IJ.pad(2 * cells_folder - 3 + channel, 2) + ".tif\n\t\ncould not be found", "The analysis is stopped at the step \"Cells images\""); } return; } if(imp.isHyperStack()) { frames = imp.getNFrames(); slices = imp.getNSlices(); imp = HyperStackConverter.toHyperStack(imp, 1, slices, frames, "default", "Grayscale"); } if(image_chosen == 0) bestFocus = KurtFocus(imp); // bestFocus = MaxFocus(imp); // IJ.run(imp, "Find focused slices", "select=100 variance=0.000 edge"); else bestFocus = new int[] { image_chosen }; imp2 = new Duplicator().run(imp, bestFocus[0], bestFocus[0]); // IJ.run("Make Substack...", " slices=" + bestFocus); // IJ.run("Make Substack...", " slices=" + 1); IJ.resetMinAndMax(imp2); try { switch (channel) { case 0: IJ.saveAsTiff(imp2, folder_cell + "Cells_01.tif"); break; case 1: IJ.saveAsTiff(imp2, folder_cell + "Cells_Ch1_01.tif"); break; case 2: IJ.saveAsTiff(imp2, folder_cell + "Cells_Ch2_01.tif"); break; case 3: IJ.saveAsTiff(imp2, folder_cell + "Cells_Ch3_01.tif"); break; } } catch (Exception e) { switch (channel) { case 0: showDialogWithImageAndCustomOkAndNoCancel("Cells images", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "Cells_01.tif" , "The analysis is stopped at the step \"Cells images\""); break; case 1: showDialogWithImageAndCustomOkAndNoCancel("Cells images", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "Cells_Ch1_01.tif", "The analysis is stopped at the step \"Cells images\""); break; case 2: showDialogWithImageAndCustomOkAndNoCancel("Cells images", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "Cells_Ch2_01.tif", "The analysis is stopped at the step \"Cells images\""); break; case 3: showDialogWithImageAndCustomOkAndNoCancel("Cells images", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "Cells_Ch3_01.tif", "The analysis is stopped at the step \"Cells images\""); break; } return; } // IJ.run("Close"); imp2.close(); } else { if(debug) { if(channel == 0) // imp = checkScale (folder + file1 + cells_folder + "_" + IJ.pad(3 * cells_folder - 1 , 2) + ".tif"); imp = checkScale (folder + file1 + cells_folder + "_" + IJ.pad((numberCh + 1) * cells_folder - 1 , 2) + ".tif"); else { imp = checkScale (folder + file1 + cells_folder + "_" + IJ.pad((numberCh + 1) * (cells_folder - 1) + channel, 2) + ".tif"); // imp = checkScale (folder + file1 + cells_folder + "_" + IJ.pad(2 * cells_folder - 1 , 2) + ".tif"); } if(imp == null) { if(!error) { error = true; if(channel == 0) showDialogWithImageAndCustomOkAndNoCancel("Cells images", "undo.png", "The following file:\n\t\n" + folder + file1 + cells_folder + "_" + IJ.pad((numberCh + 1) * cells_folder - 1 , 2) + ".tif\n\t\ncould not be found", "The analysis is stopped at the step \"Cells images\""); else showDialogWithImageAndCustomOkAndNoCancel("Cells images", "undo.png", "The following file:\n\t\n" + folder + file1 + cells_folder + "_" + IJ.pad((numberCh + 1) * (cells_folder - 1) + channel, 2) + ".tif\n\t\ncould not be found", "The analysis is stopped at the step \"Cells images\""); } return; } if(imp.isHyperStack()) { frames = imp.getNFrames(); slices = imp.getNSlices(); } try { imp = HyperStackConverter.toHyperStack(imp, 1, slices, frames, "default", "Grayscale"); } catch (Exception e) { showDialogWithImageAndCustomOkAndNoCancel("Cells images", "calculator.png", "Error while trying to transform the stack image \n" + imp.getTitle() + "\ncontaining " + imp.getStackSize() + " images into an hyperStack of\nChannels 1\nSlices " + slices + "\nFrames " + frames + "\ni.e. " + slices * frames + " images" , "The analysis is stopped at the step \"Cells images\""); return; } imp.show(); } else { if(channel == 0) imp = openStealth (folder + file1 + cells_folder + "_" + IJ.pad((numberCh + 1) * cells_folder - 1 , 2) + ".tif"); else imp = openStealth (folder + file1 + cells_folder + "_" + IJ.pad((numberCh + 1) * (cells_folder - 1) + channel, 2) + ".tif"); if(imp == null) { if(!error) { error = true; if(channel == 0) showDialogWithImageAndCustomOkAndNoCancel("Cells images", "undo.png", "The following file:\n\t\n" + folder + file1 + cells_folder + "_" + IJ.pad((numberCh + 1) * cells_folder - 1 , 2) + ".tif\n\t\ncould not be found", "The analysis is stopped at the step \"Cells images\""); else showDialogWithImageAndCustomOkAndNoCancel("Cells images", "undo.png", "The following file:\n\t\n" + folder + file1 + cells_folder + "_" + IJ.pad((numberCh + 1) * (cells_folder - 1) + channel, 2) + ".tif\n\t\ncould not be found", "The analysis is stopped at the step \"Cells images\""); } return; } if(imp.isHyperStack()) { frames = imp.getNFrames(); slices = imp.getNSlices(); } try { imp = HyperStackConverter.toHyperStack(imp, 1, slices, frames, "default", "Grayscale"); } catch (Exception e) { showDialogWithImageAndCustomOkAndNoCancel("Cells images", "calculator.png", "Error while trying to transform the stack image \n" + imp.getTitle() + "\ncontaining " + imp.getStackSize() + " images into an hyperStack of\nChannels 1\nSlices " + slices + "\nFrames " + frames + "\ni.e. " + slices * frames + " images" , "The analysis is stopped at the step \"Cells images\""); return; } // imp.show(); } if(channel != 0 && (ch & format[channel + 2]) == 0) // corresponds to mod1, mod2, mod3 { // Analysis with EDF for(frame = frames_begin; frame <= frames; frame++) { imp2 = SubHyperstackMaker.makeSubhyperstack(imp, "1", "1-" + slices, "" + frame); if(beads_sequence_images_find_focused_slices) imp2 = Find_Focused_Slices.getAlignedSlices(imp2, 80, 0.00, true, true, false); imp2.show(); IJ.run("EDF Easy mode", "quality='4' topology='0' show-topology='off' show-view='off'"); while(WindowManager.getImage("Output") == null) { IJ.wait(10); } impout = WindowManager.getImage("Output"); try { IJ.saveAs(impout, "Tiff", folder_cell + "Cells_Ch" + channel + "_" + IJ.pad(frame, 2) + ".tif"); } catch (Exception e) { showDialogWithImageAndCustomOkAndNoCancel("Cells images", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "Cells_Ch" + channel + "_" + IJ.pad(frame, 2) + ".tif", "The analysis is stopped at the step \"Cells images\""); return; } impout.close(); imp2 .close(); } } else { // Analysis with Kurtosis if(image_chosen == 0) bestFocus = KurtFocus(imp); else { bestFocus = new int[frames]; for(frame = 0; frame < frames; frame++) bestFocus[frame] = image_chosen; } for(frame = frames_begin; frame <= frames; frame++) { // imp.setPosition(1, bestFocus, frame); // IJ.run(imp, "Reduce Dimensionality...", "keep"); imp2 = new Duplicator().run(imp, 1, 1, bestFocus[frame - 1], bestFocus[frame - 1], frame, frame); IJ.resetMinAndMax(imp2); // imp2.show(); // IJ.saveAs("Tiff", folder_cell + "Cells_" + IJ.pad(frame, 2) + ".tif"); IJ.showStatus("Saving Cells_" + IJ.pad(frame, 2) + ".tif"); try { switch (channel) { case 0: IJ.saveAsTiff(imp2, folder_cell + "Cells_" + IJ.pad(frame, 2) + ".tif"); break; case 1: IJ.saveAsTiff(imp2, folder_cell + "Cells_Ch1_" + IJ.pad(frame, 2) + ".tif"); break; case 2: IJ.saveAsTiff(imp2, folder_cell + "Cells_Ch2_" + IJ.pad(frame, 2) + ".tif"); break; case 3: IJ.saveAsTiff(imp2, folder_cell + "Cells_Ch3_" + IJ.pad(frame, 2) + ".tif"); break; } } catch (Exception e) { switch (channel) { case 0: showDialogWithImageAndCustomOkAndNoCancel("Cells images", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "Cells_" + IJ.pad(frame, 2) + ".tif", "The analysis is stopped at the step \"Cells images\""); break; case 1: showDialogWithImageAndCustomOkAndNoCancel("Cells images", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "Cells_Ch1_" + IJ.pad(frame, 2) + ".tif", "The analysis is stopped at the step \"Cells images\""); break; case 2: showDialogWithImageAndCustomOkAndNoCancel("Cells images", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "Cells_Ch2_" + IJ.pad(frame, 2) + ".tif", "The analysis is stopped at the step \"Cells images\""); break; case 3: showDialogWithImageAndCustomOkAndNoCancel("Cells images", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "Cells_Ch3_" + IJ.pad(frame, 2) + ".tif", "The analysis is stopped at the step \"Cells images\""); break; } return; } // IJ.run("Close"); imp2.close(); } } if(debug) IJ.run("Close"); else imp.close(); } // updating and saving "JEasyTFM_x_end.txt" file if(channel == 0 || channel == 3) { if(cells_starting_folder < cells_ending_folder) cells_starting_folder++; else { cells_images = false; cells_starting_folder = 1; } saveJob(folder + "Jobs" + File.separator + "JEasyTFM_" + job_index + "_end.txt"); } /////////////////////////////////////////////////// } if((ch & 0x1) == 0 && (ch & 0x2) == 0 && (ch & 0x4) == 0) channel--; } } // cells_images private void beads_reference_images() { ImagePlus imp, imp2, impout; int beads_reference_folder, bead; String folder_begin, folder_cell; // for(bead = 1; bead <= format.length && bead != 0; bead++) for(bead = 1; bead <= 2 && bead != 0; bead++) { if(beads == 0) bead = 0; else if((beads & format[bead - 1]) == 0) continue; for(beads_reference_folder = beads_reference_starting_folder; beads_reference_folder <= beads_reference_ending_folder; beads_reference_folder++) { folder_begin = folder.substring(0, folder.length() - 1) + link + "Reference" + File.separator; folder_cell = folder + "Cell " + beads_reference_folder + File.separator; imp = null; if(beads == 0) { imp = IJ.openImage(folder_begin + file2 + beads_reference_folder + "_" + IJ.pad(2 * beads_reference_folder, 2) + ".tif"); if(imp == null) { if(!error) { error = true; showDialogWithImageAndCustomOkAndNoCancel("Beads reference images", "undo.png", "The following file:\n\t\n" + folder_begin + file2 + beads_reference_folder + "_" + IJ.pad(2 * beads_reference_folder, 2) + ".tif\n\t\ncould not be found", "The analysis is stopped at the step \"Beads reference images\""); } return; } // imp = IJ.openImage(folder_begin + file2 + beads_reference_folder + "_" + IJ.pad(3 * beads_reference_folder, 2) + ".tif"); if(beads_reference_images_find_focused_slices) imp = Find_Focused_Slices.getAlignedSlices(imp, 80, 0.00, true, true, false); imp.show(); IJ.run("EDF Easy mode", "quality='4' topology='0' show-topology='off' show-view='off'"); while(WindowManager.getImage("Output") == null) { IJ.wait(10); } impout = WindowManager.getImage("Output"); try { IJ.saveAs(impout, "Tiff", folder_cell + "BeadsReference.tif"); } catch (Exception e) { showDialogWithImageAndCustomOkAndNoCancel("Beads reference images", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "BeadsReference.tif", "The analysis is stopped at the step \"Beads reference images\""); return; } impout.close(); } else { // imp = IJ.openImage(folder_begin + file2 + beads_reference_folder + "_" + beads_reference_folder + ".tif"); // imp = IJ.openImage(folder_begin + file2 + beads_reference_folder + "_" + IJ.pad(beads_reference_folder, 2) + ".tif"); // imp = IJ.openImage(folder_begin + file2 + beads_reference_folder + "_" + IJ.pad(3 * beads_reference_folder, 2) + ".tif"); imp = IJ.openImage(folder_begin + file2 + beads_reference_folder + "_" + IJ.pad(2 * beads_reference_folder, 2) + ".tif"); // imp = HyperStackConverter.toHyperStack(imp, 3, slices, frames, "default", "Grayscale"); if(imp == null) { if(!error) { error = true; showDialogWithImageAndCustomOkAndNoCancel("Beads reference images", "undo.png", "The following file:\n\t\n" + folder_begin + file2 + beads_reference_folder + "_" + IJ.pad(2 * beads_reference_folder, 2) + ".tif\n\t\ncould not be found", "The analysis is stopped at the step \"Beads reference images\""); } return; } if(imp.isHyperStack()) { // frames = imp.getNFrames(); slices = imp.getNSlices(); } try { imp = HyperStackConverter.toHyperStack(imp, 2, slices, 1 , "default", "Grayscale"); } catch (Exception e) { showDialogWithImageAndCustomOkAndNoCancel("Beads reference images", "calculator.png", "Error while trying to transform the stack image \n" + imp.getTitle() + "\ncontaining " + imp.getStackSize() + " images into an hyperStack of\nChannels 2\nSlices " + slices + "\nFrames 1\ni.e. " + 2 * slices + " images" , "The analysis is stopped at the step \"Beads reference images\""); return; } // imp.show(); imp2 = SubHyperstackMaker.makeSubhyperstack(imp, "" + bead, "1-" + slices, "1"); if(beads_reference_images_find_focused_slices) imp2 = Find_Focused_Slices.getAlignedSlices(imp2, 80, 0.00, true, true, false); imp2.show(); IJ.run("EDF Easy mode", "quality='4' topology='0' show-topology='off' show-view='off'"); while(WindowManager.getImage("Output") == null) { IJ.wait(10); } impout = WindowManager.getImage("Output"); try { IJ.saveAs(impout, "Tiff", folder_cell + "BeadsReference_" + bead + ".tif"); } catch (Exception e) { showDialogWithImageAndCustomOkAndNoCancel("Beads reference images", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "BeadsReference_" + bead + ".tif", "The analysis is stopped at the step \"Beads reference images\""); return; } impout.close(); imp2 .close(); } imp.close(); // updating and saving "JEasyTFM_x_end.txt" file if(bead == 0 || bead == 2) { if(beads_reference_starting_folder < beads_reference_ending_folder) beads_reference_starting_folder++; else { beads_reference_images = false; beads_reference_starting_folder = 1; } saveJob(folder + "Jobs" + File.separator + "JEasyTFM_" + job_index + "_end.txt"); } /////////////////////////////////////////////////// } if(beads == 0) bead--; } } // beads_reference_images private void beads_sequence_images() { ImagePlus imp = null; ImagePlus imp1 = null; ImagePlus imp2 = null; ImagePlus imp3 = null; ImagePlus impout = null; int beads_sequence_folder, bead; int frame; String folder_begin, folder_cell; // for(bead = 1; bead <= format.length && bead != 0; bead++) for(bead = 1; bead <= 2 && bead != 0; bead++) { if(beads == 0) bead = 0; else if((beads & format[bead - 1]) == 0) continue; for(beads_sequence_folder = beads_sequence_starting_folder; beads_sequence_folder <= beads_sequence_ending_folder; beads_sequence_folder++) { folder_cell = folder + "Cell " + beads_sequence_folder + File.separator; if(beads == 0) { // imp = openStealth (folder + file1 + beads_sequence_folder + "_" + IJ.pad((numberCh + 1) * beads_sequence_folder - numberCh - 1 + u, 2) + ".tif"); imp = IJ.openImage(folder + file1 + String.valueOf(beads_sequence_folder) + "_" + IJ.pad((numberCh + 1) * beads_sequence_folder, 2) + ".tif"); // imp = IJ.openImage(folder + file1 + String.valueOf(beads_sequence_folder) + "_" + IJ.pad(2 * beads_sequence_folder, 2) + ".tif"); if(imp == null) { imp1 = IJ.openImage(folder + file1 + String.valueOf(beads_sequence_folder) + "_" + IJ.pad((numberCh + 1) * beads_sequence_folder, 2) + "_p1.tif"); if(imp1 == null) { if(!error) { error = true; showDialogWithImageAndCustomOkAndNoCancel("Beads sequence images", "undo.png", "The following file:\n\t\n" + folder + file1 + String.valueOf(beads_sequence_folder) + "_" + IJ.pad(2 * beads_sequence_folder, 2) + "_p1.tif\n\t\ncould not be found", "The analysis is stopped at the step \"Beads sequence images\""); } return; } imp2 = IJ.openImage(folder + file1 + String.valueOf(beads_sequence_folder) + "_" + IJ.pad((numberCh + 1) * beads_sequence_folder, 2) + "_p2.tif"); imp3 = IJ.openImage(folder + file1 + String.valueOf(beads_sequence_folder) + "_" + IJ.pad((numberCh + 1) * beads_sequence_folder, 2) + "_p3.tif"); if(imp1 != null && imp2 != null) { if(imp3 != null) { imp = Concatenator.run(imp1, imp2, imp3); imp3.close(); } else imp = Concatenator.run(imp1, imp2); // imp .show(); imp1.close(); imp2.close(); } else if(imp2 == null) { if(!error) { error = true; showDialogWithImageAndCustomOkAndNoCancel("Beads sequence images", "undo.png", "The following file:\n\t\n" + folder + file1 + String.valueOf(beads_sequence_folder) + "_" + IJ.pad(2 * beads_sequence_folder, 2) + "_p1.tif\n\t\ncould not be found", "The analysis is stopped at the step \"Beads sequence images\""); } imp1.close(); return; } } if(imp.isHyperStack()) { frames = imp.getNFrames(); slices = imp.getNSlices(); } try { imp = HyperStackConverter.toHyperStack(imp, 1, slices, frames, "default", "Grayscale"); } catch (Exception e) { showDialogWithImageAndCustomOkAndNoCancel("Beads reference images", "calculator.png", "Error while trying to transform the stack image \n" + imp.getTitle() + "\ncontaining " + imp.getStackSize() + " images into an hyperStack of\nChannels 1\nSlices " + slices + "\nFrames " + frames + "\ni.e. " + slices * frames + " images" , "The analysis is stopped at the step \"Beads reference images\""); return; } // imp.show(); for(frame = frames_begin; frame <= frames; frame++) { imp2 = SubHyperstackMaker.makeSubhyperstack(imp, "1", "1-" + slices, "" + frame); if(beads_sequence_images_find_focused_slices) imp2 = Find_Focused_Slices.getAlignedSlices(imp2, 80, 0.00, true, true, false); imp2.show(); IJ.run("EDF Easy mode", "quality='4' topology='0' show-topology='off' show-view='off'"); while(WindowManager.getImage("Output") == null) { IJ.wait(10); } impout = WindowManager.getImage("Output"); try { IJ.saveAs(impout, "Tiff", folder_cell + "BeadsAfter_" + IJ.pad(frame, 2) + ".tif"); } catch (Exception e) { showDialogWithImageAndCustomOkAndNoCancel("Beads sequence images", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "BeadsAfter_" + IJ.pad(frame, 2) + ".tif", "The analysis is stopped at the step \"Beads sequence images\""); return; } impout.close(); imp2 .close(); } } else { imp = IJ.openImage(folder + file1 + String.valueOf(beads_sequence_folder) + "_" + IJ.pad(2 * beads_sequence_folder, 2) + ".tif"); // imp = IJ.openImage(folder + getFileName(folder, file1, beads_sequence_folder)); if(imp == null) { imp1 = IJ.openImage(folder + file1 + String.valueOf(beads_sequence_folder) + "_" + IJ.pad(2 * beads_sequence_folder, 2) + "_p1.tif"); if(imp1 == null) { if(!error) { error = true; showDialogWithImageAndCustomOkAndNoCancel("Beads sequence images", "undo.png", "The following file:\n\t\n" + folder + file1 + String.valueOf(beads_sequence_folder) + "_" + IJ.pad(2 * beads_sequence_folder, 2) + "_p1.tif\n\t\ncould not be found", "The analysis is stopped at the step \"Beads sequence images\""); } return; } imp2 = IJ.openImage(folder + file1 + String.valueOf(beads_sequence_folder) + "_" + IJ.pad(2 * beads_sequence_folder, 2) + "_p2.tif"); if(imp2 == null) { if(!error) { error = true; showDialogWithImageAndCustomOkAndNoCancel("Beads sequence images", "undo.png", "The following file:\n\t\n" + folder + file1 + String.valueOf(beads_sequence_folder) + "_" + IJ.pad(2 * beads_sequence_folder, 2) + "_p2.tif\n\t\ncould not be found", "The analysis is stopped at the step \"Beads sequence images\""); } imp1.close(); return; } imp = Concatenator.run(imp1, imp2); imp1 .close(); imp2 .close(); } if(imp.isHyperStack()) { frames = imp.getNFrames(); slices = imp.getNSlices(); } try { // imp = HyperStackConverter.toHyperStack(imp, 3, slices, frames, "default", "Grayscale"); imp = HyperStackConverter.toHyperStack(imp, 2, slices, frames, "default", "Grayscale"); } catch (Exception e) { showDialogWithImageAndCustomOkAndNoCancel("Beads reference images", "calculator.png", "Error while trying to transform the stack image \n" + imp.getTitle() + "\ncontaining " + imp.getStackSize() + " images into an hyperStack of\nChannels 2\nSlices " + slices + "\nFrames " + frames + "\ni.e. " + 2 * slices * frames + " images" , "The analysis is stopped at the step \"Beads reference images\""); return; } // imp.show(); for(frame = frames_begin; frame <= frames; frame++) { imp2 = SubHyperstackMaker.makeSubhyperstack(imp, "" + bead, "1-" + slices, "" + frame); if(beads_sequence_images_find_focused_slices) imp2 = Find_Focused_Slices.getAlignedSlices(imp2, 80, 0.00, true, true, false); imp2.show(); IJ.run("EDF Easy mode", "quality='4' topology='0' show-topology='off' show-view='off'"); while(WindowManager.getImage("Output") == null) { IJ.wait(10); } impout = WindowManager.getImage("Output"); try { IJ.saveAs(impout, "Tiff", folder_cell + "BeadsAfter_" + bead + "_" + IJ.pad(frame, 2) + ".tif"); } catch (Exception e) { showDialogWithImageAndCustomOkAndNoCancel("Beads sequence images", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "BeadsAfter_" + bead + "_" + IJ.pad(frame, 2) + ".tif", "The analysis is stopped at the step \"Beads sequence images\""); return; } impout.close(); imp2 .close(); } // imp2 = SubHyperstackMaker.makeSubhyperstack(imp, "" + 3, "" + slices, "1"); // imp2.show(); // IJ.saveAsTiff(imp2, folder_cell + "Cells_01.tif"); // imp2.close(); } imp.close(); // updating and saving "JEasyTFM_x_end.txt" file if(bead == 0 || bead == 2) { if(beads_sequence_starting_folder < beads_sequence_ending_folder) beads_sequence_starting_folder++; else { beads_sequence_images = false; beads_sequence_starting_folder = 1; } saveJob(folder + "Jobs" + File.separator + "JEasyTFM_" + job_index + "_end.txt"); } /////////////////////////////////////////////////// } if(beads == 0) bead--; } } // beads_sequence_images private void traction_force() { ImagePlus imp1, imp2, stackImp, impProj; ImageProcessor ip1 , ip2 , stackIp, stackIp2; ImageStack is; ImageConverter converter; ZProjector zproj; Roi roi; String folder_cell, str; int traction_folder, bead, channel, frame; int widthCorr = 0; int heightCorr = 0; double scaleMin; double scaleMax; double dx, dy; double x, y, width, height; int [] delta, dim; double [] displacement; double [] scale; FileOutputStream fos; BufferedOutputStream bos; PrintWriter writer; // for(bead = 1; bead <= format.length && bead != 0; bead++) for(bead = 1; bead <= 2 && bead != 0; bead++) { if(beads == 0) bead = 0; else if((beads & format[bead - 1]) == 0) continue; for(traction_folder = traction_starting_folder; traction_folder <= traction_ending_folder; traction_folder++) { folder_cell = folder + "Cell " + traction_folder + File.separator; scale = new double[frames]; // dx = dy = 0; // f = File.open(folder_cell + "table.txt"); if(traction_force_alignment) { if(traction_force_alignment_make) { // Creating the aligned images for(frame = frames_begin; frame <= frames; frame++) { imp1 = imp2 = null; if(beads == 0) { // imp1 = IJ.openImage(folder_cell + "BeadsReference.tif"); // imp1.show(); // imp1 = IJ.openImage(folder_cell + "BeadsAfter_" + IJ.pad(frame, 2) + ".tif"); // imp1.show(); imp1 = IJ.openImage(folder_cell + "BeadsReference.tif"); if(imp1 == null) { if(!error) { error = true; showDialogWithImageAndCustomOkAndNoCancel("Traction force alignment make", "undo.png", "The following file:\n\t\n" + folder_cell + "BeadsReference.tif\n\t\ncould not be found", "The analysis is stopped at the step \"Traction force alignment make\""); } return; } IJ.run (imp1, "Subtract Background...", "rolling=10 sliding"); IJ.run (imp1, "Enhance Contrast..." , "saturated=0.4 normalize"); is = imp1.getStack(); imp2 = IJ.openImage(folder_cell + "BeadsAfter_" + IJ.pad(frame, 2) + ".tif"); if(imp2 == null) { if(!error) { error = true; showDialogWithImageAndCustomOkAndNoCancel("Traction force alignment make", "undo.png", "The following file:\n\t\n" + folder_cell + "BeadsAfter_" + IJ.pad(frame, 2) + ".tif\n\t\ncould not be found", "The analysis is stopped at the step \"Traction force alignment make\""); } imp1.close(); return; } IJ.run (imp2, "Subtract Background...", "rolling=10 sliding"); IJ.run (imp2, "Enhance Contrast..." , "saturated=0.4 normalize"); ip2 = imp2.getProcessor(); is .addSlice(ip2); stackImp = new ImagePlus("Stack", is); // stackImp .show(); imp1 .close(); imp2 .close(); } else { // imp1 = IJ.openImage(folder_cell + "BeadsReference_" + bead + ".tif"); // imp1.show(); // imp1 = IJ.openImage(folder_cell + "BeadsAfter_" + bead + "_" + IJ.pad(frame, 2) + ".tif"); // imp1.show(); imp1 = IJ.openImage(folder_cell + "BeadsReference_" + bead + ".tif"); if(imp1 == null) { if(!error) { error = true; showDialogWithImageAndCustomOkAndNoCancel("Traction force alignment make", "undo.png", "The following file:\n\t\n" + folder_cell + "BeadsReference_" + bead + ".tif\n\t\ncould not be found", "The analysis is stopped at the step \"Traction force alignment make\""); } return; } is = imp1.getStack(); imp2 = IJ.openImage(folder_cell + "BeadsAfter_" + bead + "_" + IJ.pad(frame, 2) + ".tif"); if(imp2 == null) { if(!error) { error = true; showDialogWithImageAndCustomOkAndNoCancel("Traction force alignment make", "undo.png", "The following file:\n\t\n" + folder_cell + "BeadsAfter_" + bead + "_" + IJ.pad(frame, 2) + ".tif\n\t\ncould not be found", "The analysis is stopped at the step \"Traction force alignment make\""); } imp1.close(); return; } ip2 = imp2.getProcessor(); is .addSlice(ip2); stackImp = new ImagePlus("Stack", is); // stackImp .show(); imp1 .close(); imp2 .close(); } // IJ.run("Images to Stack", "name=Stack title=[] use"); // IJ.run("16-bit"); converter = new ImageConverter(stackImp); converter .convertToGray16(); // stackImp.show(); // IJ.run("Align slices in stack...", "method=5 windowsizex=604 windowsizey=602 x0=200 y0=200 swindow=0 subpixel=false itpmethod=0 ref.slice=1 show=true"); // IJ.run("Align slices in stack...", "method=5 windowsizex=250 windowsizey=250 x0=16 y0=681 swindow=0 subpixel=false itpmethod=0 ref.slice=1 show=true"); // IJ.run("Align slices in stack...", "method=5 windowsizex=250 windowsizey=250 x0=370 y0=940 swindow=0 subpixel=false itpmethod=0 ref.slice=1 show=true"); // IJ.run("Align slices in stack...", "method=5 windowsizex=311 windowsizey=281 x0=34 y0=488 swindow=0 subpixel=false itpmethod=0 ref.slice=1 show=true"); // IJ.run("Align slices in stack...", "method=5 windowsizex=300 windowsizey=300 x0=35 y0=490 swindow=0 subpixel=false itpmethod=0 ref.slice=1 show=true"); // IJ.run("Align slices in stack...", "method=5 windowsizex=404 windowsizey=371 x0=613 y0=606 swindow=0 subpixel=false itpmethod=0 ref.slice=1 show=true"); // IJ.run("Align slices in stack...", "method=5 windowsizex=404 windowsizey=371 x0=613 y0=606 swindow=0 subpixel=true itpmethod=1 ref.slice=1 show=true"); displacement = TemplateMatching.Align_slices.getAlignSlicesDisplacement(stackImp, "Normalized correlation coefficient", 72, 137, 455, 341, 0, true, "Bicubic", 1, false); // displacement = TemplateMatching.Align_slices.getAlignSlicesDisplacement(stackImp, "Normalized correlation coefficient", 404, 371, 613, 606, 0, true, "Bicubic", 1, false); // displacement = TemplateMatching.Align_slices.getAlignSlicesDisplacement(stackImp, "Normalized correlation coefficient", stackImp.getWidth() / 8, stackImp.getHeight() / 8, stackImp.getWidth() * 3 / 4, stackImp.getHeight() * 3 / 4, 0, true, "Bicubic", 1, false); // stackImp.deleteRoi(); // closeWindow("Log"); // dx2 = getResult("dX", 0); // dy2 = getResult("dY", 0); dx = displacement[0]; dy = displacement[1]; // closeWindow("Results"); // IJ.run("Stack to Images"); // if(beads == 0) // IJ.selectWindow("BeadsReference"); // else // IJ.selectWindow("BeadsReference_" + bead); if(frame == 1) { imp1 = new Duplicator().run(stackImp, 1, 1); try { if(beads == 0) { checkAndCreateFolder( folder_cell + "Analysis"); // IJ.saveAs ("Tiff" , folder_cell + "Analysis" + File.separator + "CorrBeadsReference.tif"); IJ.saveAsTiff (imp1 , folder_cell + "Analysis" + File.separator + "CorrBeadsReference.tif"); IJ.saveString ("Displacement data\n" , folder_cell + "Analysis" + File.separator + "Transformation.txt"); } else { checkAndCreateFolder( folder_cell + "Analysis_" + bead); // IJ.saveAs ("Tiff" , folder_cell + "Analysis_" + bead + File.separator + "CorrBeadsReference_" + bead + ".tif"); IJ.saveAsTiff (imp1 , folder_cell + "Analysis_" + bead + File.separator + "CorrBeadsReference_" + bead + ".tif"); IJ.saveString ("Displacement data\n" , folder_cell + "Analysis_" + bead + File.separator + "Transformation.txt"); } imp1.close(); } catch (Exception e) { if(beads == 0) showDialogWithImageAndCustomOkAndNoCancel("Traction force alignment make", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "Analysis" + File.separator + "CorrBeadsReference.tif" , "The analysis is stopped at the step \"Traction force alignment make\""); else showDialogWithImageAndCustomOkAndNoCancel("Traction force alignment make", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "Analysis_" + bead + File.separator + "CorrBeadsReference_" + bead + ".tif", "The analysis is stopped at the step \"Traction force alignment make\""); return; } } // IJ.run("Close"); // if(beads == 0) // IJ.selectWindow("BeadsAfter_" + IJ.pad(frame, 2)); // else // IJ.selectWindow("BeadsAfter_" + bead + "_" + IJ.pad(frame, 2)); imp2 = new Duplicator().run(stackImp, 2, 2); stackImp.close(); // print(f, dx + " \t" + dy + " \t" + dx + " \t" + dy + " \t" + getPositionX1() + " \t" + getPositionX2() + " \t" + getPositionY1() + " \t" + getPositionY2()); if(frame == 1) { if(beads == 0) { checkAndCreateFolder(folder_cell + "CorrBeadsAfter"); checkAndCreateFolder(folder_cell + "CorrCells"); } else { checkAndCreateFolder(folder_cell + "CorrBeadsAfter_" + bead); checkAndCreateFolder(folder_cell + "CorrCells_" + bead); } } try { if(beads == 0) // IJ.saveAs("Tiff" , folder_cell + "CorrBeadsAfter" + File.separator + "CorrBeadsAfter_" + IJ.pad(frame, 2) + ".tif"); IJ.saveAsTiff(imp2, folder_cell + "CorrBeadsAfter" + File.separator + "CorrBeadsAfter_" + IJ.pad(frame, 2) + ".tif"); else // IJ.saveAs("Tiff" , folder_cell + "CorrBeadsAfter_" + bead + File.separator + "CorrBeadsAfter_" + bead + "_" + IJ.pad(frame, 2) + ".tif"); IJ.saveAsTiff(imp2, folder_cell + "CorrBeadsAfter_" + bead + File.separator + "CorrBeadsAfter_" + bead + "_" + IJ.pad(frame, 2) + ".tif"); // IJ.run("Close"); imp2.close(); } catch (Exception e) { if(beads == 0) showDialogWithImageAndCustomOkAndNoCancel("Traction force alignment make", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "CorrBeadsAfter" + File.separator + "CorrBeadsAfter_" + IJ.pad(frame, 2) + ".tif", "The analysis is stopped at the step \"Traction force alignment make\""); else showDialogWithImageAndCustomOkAndNoCancel("Traction force alignment make", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "CorrBeadsAfter_" + bead + File.separator + "CorrBeadsAfter_" + bead + "_" + IJ.pad(frame, 2) + ".tif", "The analysis is stopped at the step \"Traction force alignment make\""); return; } for(channel = 1; channel <= numberCh && channel != 0; channel++) { imp1 = null; if((ch & 0x1) == 0 && (ch & 0x2) == 0 && (ch & 0x4) == 0) channel = 0; else if((ch & format[channel - 1]) == 0) continue; // imp1 = IJ.openImage(folder_cell + "Cells_" + IJ.pad(frame, 2) + ".tif"); switch (channel) { case 0: imp1 = IJ.openImage(folder_cell + "Cells_" + IJ.pad(frame, 2) + ".tif"); break; case 1: imp1 = IJ.openImage(folder_cell + "Cells_Ch1_" + IJ.pad(frame, 2) + ".tif"); break; case 2: imp1 = IJ.openImage(folder_cell + "Cells_Ch2_" + IJ.pad(frame, 2) + ".tif"); break; case 3: imp1 = IJ.openImage(folder_cell + "Cells_Ch3_" + IJ.pad(frame, 2) + ".tif"); break; } if(imp1 == null) { switch (channel) { case 0: showDialogWithImageAndCustomOkAndNoCancel("Traction force alignment make", "undo.png", "The following file:\n\t\n" + folder_cell + "Cells_" + IJ.pad(frame, 2) + ".tif\n\t\ncould not be found", "The analysis is stopped at the step \"Traction force alignment make\""); break; case 1: showDialogWithImageAndCustomOkAndNoCancel("Traction force alignment make", "undo.png", "The following file:\n\t\n" + folder_cell + "Cells_Ch1_" + IJ.pad(frame, 2) + ".tif\n\t\ncould not be found", "The analysis is stopped at the step \"Traction force alignment make\""); break; case 2: showDialogWithImageAndCustomOkAndNoCancel("Traction force alignment make", "undo.png", "The following file:\n\t\n" + folder_cell + "Cells_Ch2_" + IJ.pad(frame, 2) + ".tif\n\t\ncould not be found", "The analysis is stopped at the step \"Traction force alignment make\""); break; case 3: showDialogWithImageAndCustomOkAndNoCancel("Traction force alignment make", "undo.png", "The following file:\n\t\n" + folder_cell + "Cells_Ch3_" + IJ.pad(frame, 2) + ".tif\n\t\ncould not be found", "The analysis is stopped at the step \"Traction force alignment make\""); break; } return; } // ip1 = imp1.getProcessor(); // ip1.translate(dx, dy); IJ.run(imp1, "Translate...", "x=" + dx + " y=" + dy + " interpolation=Bicubic"); str = frame + "\t" + dx + "\t" + dy; try { if(beads == 0) { // IJ.saveAs(imp1, "Tiff", folder_cell + "CorrCells" + File.separator + "CorrCells_" + IJ.pad(frame, 2) + ".tif"); switch (channel) { case 0: IJ.saveAsTiff(imp1, folder_cell + "CorrCells" + File.separator + "CorrCells_" + IJ.pad(frame, 2) + ".tif"); break; case 1: IJ.saveAsTiff(imp1, folder_cell + "CorrCells" + File.separator + "CorrCells_Ch1_" + IJ.pad(frame, 2) + ".tif"); break; case 2: IJ.saveAsTiff(imp1, folder_cell + "CorrCells" + File.separator + "CorrCells_Ch2_" + IJ.pad(frame, 2) + ".tif"); break; case 3: IJ.saveAsTiff(imp1, folder_cell + "CorrCells" + File.separator + "CorrCells_Ch3_" + IJ.pad(frame, 2) + ".tif"); break; } IJ.append(str, folder_cell + "Analysis" + File.separator + "Transformation.txt"); } else { // IJ.saveAs(imp1, "Tiff", folder_cell + "CorrCells_" + bead + File.separator + "CorrCells_" + bead + "_" + IJ.pad(frame, 2) + ".tif"); switch (channel) { case 0: IJ.saveAsTiff(imp1, folder_cell + "CorrCells_" + bead + File.separator + "CorrCells_" + bead + "_" + IJ.pad(frame, 2) + ".tif"); break; case 1: IJ.saveAsTiff(imp1, folder_cell + "CorrCells_" + bead + File.separator + "CorrCells_" + bead + "_Ch1_" + IJ.pad(frame, 2) + ".tif"); break; case 2: IJ.saveAsTiff(imp1, folder_cell + "CorrCells_" + bead + File.separator + "CorrCells_" + bead + "_Ch2_" + IJ.pad(frame, 2) + ".tif"); break; case 3: IJ.saveAsTiff(imp1, folder_cell + "CorrCells_" + bead + File.separator + "CorrCells_" + bead + "_Ch3_" + IJ.pad(frame, 2) + ".tif"); break; } IJ.append(str, folder_cell + "Analysis_" + bead + File.separator + "Transformation.txt"); } imp1.close(); } catch (Exception e) { if(beads == 0) { switch (channel) { case 0: showDialogWithImageAndCustomOkAndNoCancel("Traction force alignment make", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "CorrCells" + File.separator + "CorrCells_" + IJ.pad(frame, 2) + ".tif", "The analysis is stopped at the step \"Traction force alignment make\""); break; case 1: showDialogWithImageAndCustomOkAndNoCancel("Traction force alignment make", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "CorrCells" + File.separator + "CorrCells_Ch1_" + IJ.pad(frame, 2) + ".tif", "The analysis is stopped at the step \"Traction force alignment make\""); break; case 2: showDialogWithImageAndCustomOkAndNoCancel("Traction force alignment make", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "CorrCells" + File.separator + "CorrCells_Ch2_" + IJ.pad(frame, 2) + ".tif", "The analysis is stopped at the step \"Traction force alignment make\""); break; case 3: showDialogWithImageAndCustomOkAndNoCancel("Traction force alignment make", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "CorrCells" + File.separator + "CorrCells_Ch3_" + IJ.pad(frame, 2) + ".tif", "The analysis is stopped at the step \"Traction force alignment make\""); break; } } else { switch (channel) { case 0: showDialogWithImageAndCustomOkAndNoCancel("Traction force alignment make", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "CorrCells_" + bead + File.separator + "CorrCells_" + bead + "_" + IJ.pad(frame, 2) + ".tif", "The analysis is stopped at the step \"Traction force alignment make\""); break; case 1: showDialogWithImageAndCustomOkAndNoCancel("Traction force alignment make", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "CorrCells_" + bead + File.separator + "CorrCells_" + bead + "_Ch1_" + IJ.pad(frame, 2) + ".tif", "The analysis is stopped at the step \"Traction force alignment make\""); break; case 2: showDialogWithImageAndCustomOkAndNoCancel("Traction force alignment make", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "CorrCells_" + bead + File.separator + "CorrCells_" + bead + "_Ch2_" + IJ.pad(frame, 2) + ".tif", "The analysis is stopped at the step \"Traction force alignment make\""); break; case 3: showDialogWithImageAndCustomOkAndNoCancel("Traction force alignment make", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "CorrCells_" + bead + File.separator + "CorrCells_" + bead + "_Ch3_" + IJ.pad(frame, 2) + ".tif", "The analysis is stopped at the step \"Traction force alignment make\""); break; } } return; } if((ch & 0x1) == 0 && (ch & 0x2) == 0 && (ch & 0x4) == 0) channel--; } } // File.close(f); // updating and saving "JEasyTFM_x_end.txt" file if((bead == 0 || bead == 2) && traction_folder == traction_ending_folder) { traction_force_alignment_make = false; saveJob(folder + "Jobs" + File.separator + "JEasyTFM_" + job_index + "_end.txt"); } } // traction_force_alignment_make if(traction_force_alignment_crop) { // generating the ROI frame = 1; if(beads == 0) { imp1 = null; imp1 = IJ.openImage (folder_cell + "CorrBeadsAfter" + File.separator + "CorrBeadsAfter_" + IJ.pad(frame, 2) + ".tif"); if(imp1 == null) { if(!error) { error = true; showDialogWithImageAndCustomOkAndNoCancel("Traction force alignment crop", "undo.png", "The following file:\n\t\n" + folder_cell + "CorrBeadsAfter" + File.separator + "CorrBeadsAfter_" + IJ.pad(frame, 2) + ".tif\n\t\ncould not be found", "The analysis is stopped at the step \"Traction force alignment crop\""); } return; } is = imp1.getStack(); for(frame = 2; frame <= frames; frame++) { imp2 = null; imp2 = IJ.openImage(folder_cell + "CorrBeadsAfter" + File.separator + "CorrBeadsAfter_" + IJ.pad(frame, 2) + ".tif"); if(imp2 == null) { if(!error) { error = true; showDialogWithImageAndCustomOkAndNoCancel("Traction force alignment crop", "undo.png", "The following file:\n\t\n" + folder_cell + "CorrBeadsAfter" + File.separator + "CorrBeadsAfter_" + IJ.pad(frame, 2) + ".tif\n\t\ncould not be found", "The analysis is stopped at the step \"Traction force alignment crop\""); } return; } ip2 = imp2.getProcessor(); is .addSlice(ip2); imp2 .close(); } } else { imp1 = null; imp1 = IJ.openImage (folder_cell + "CorrBeadsAfter_" + bead + File.separator + "CorrBeadsAfter_" + bead + "_" + IJ.pad(frame, 2) + ".tif"); if(imp1 == null) { if(!error) { error = true; showDialogWithImageAndCustomOkAndNoCancel ("Traction force alignment crop", "undo.png", "The following file:\n\t\n" + folder_cell + "CorrBeadsAfter_" + bead + File.separator + "CorrBeadsAfter_" + bead + "_" + IJ.pad(frame, 2) + ".tif\n\t\ncould not be found", "The analysis is stopped at the step \"Traction force alignment crop\""); } return; } is = imp1.getStack(); for(frame = 2; frame <= frames; frame++) { imp2 = null; imp2 = IJ.openImage(folder_cell + "CorrBeadsAfter_" + bead + File.separator + "CorrBeadsAfter_" + bead + "_" + IJ.pad(frame, 2) + ".tif"); if(imp2 == null) { if(!error) { error = true; showDialogWithImageAndCustomOkAndNoCancel("Traction force alignment crop", "undo.png", "The following file:\n\t\n" + folder_cell + "CorrBeadsAfter_" + bead + File.separator + "CorrBeadsAfter_" + bead + "_" + IJ.pad(frame, 2) + ".tif\n\t\ncould not be found", "The analysis is stopped at the step \"Traction force alignment crop\""); } return; } ip2 = imp2.getProcessor(); is .addSlice(ip2); imp2 .close(); } } stackImp = new ImagePlus("Stack", is); imp1.close(); // stackImp .show(); // IJ.run("Z Project...", "projection=[Min Intensity]"); zproj = new ZProjector(stackImp); zproj.setStartSlice(1); zproj.setStopSlice (is.getSize()); zproj.setMethod(ZProjector.MIN_METHOD); zproj.doProjection(); impProj = zproj.getProjection(); // impProj = ZProjector.run(stackImp, "min"); /* if(dx >= 0) hx = Math.round(dx / 2); else hx = IJ.getImage().getWidth() + Math.round(dx / 2); if(dy >= 0) hy = Math.round(dy / 2); else hy = IJ.getImage().getHeight() + Math.round(dy / 2); IJ.doWand(hx, hy); IJ.run("Make Inverse"); */ str = "Croping data\n" + getPositionX1(impProj) + "\t" + getPositionY1(impProj) + "\t" + (getPositionX2(impProj) - getPositionX1(impProj) + 1) + "\t" + (getPositionY2(impProj) - getPositionY1(impProj) + 1); if(beads == 0) IJ.append(str, folder_cell + "Analysis" + File.separator + "Transformation.txt"); else IJ.append(str, folder_cell + "Analysis_" + bead + File.separator + "Transformation.txt"); // IJ.makeRectangle(getPositionX1(), getPositionY1(), getPositionX2() - getPositionX1() + 1, getPositionY2() - getPositionY1() + 1); impProj.setRoi (getPositionX1(impProj), getPositionY1(impProj), getPositionX2(impProj) - getPositionX1(impProj) + 1, getPositionY2(impProj) - getPositionY1(impProj) + 1); impProj.close(); // getting the ROI position and size // IJ.run("Restore Selection"); stackImp.restoreRoi(); // getBoundingRect(x, y, width, height); roi = stackImp.getRoi(); if(roi != null) { Rectangle2D.Double r = roi.getFloatBounds(); x = r.x; y = r.y; width = r.width; height = r.height; } else x = y = width = height = 0; // croping and saving the beads time images // stackIp = stackImp.getProcessor(); // stackIp2 = stackIp .crop(); IJ.run(stackImp, "Crop", ""); // getDimensions(widthCorr, heightCorr, channelsCorr, slicesCorr, framesCorr); // stackImp = new ImagePlus("Croped stack", stackIp2); // stackImp.show(); dim = stackImp.getDimensions(); widthCorr = dim[0]; heightCorr = dim[1]; // images cleaning - code from Mickael Schmid // IJ.run(stackImp, "Thresholded Blur", "radius=3 threshold=1000 softness=0.50 strength=1 stack"); // IJ.run(stackImp, "Subtract Background...", "rolling=0.2 sliding stack"); for(frame = frames_begin; frame <= frames; frame++) { // IJ.run("Make Substack...", " slices=" + frame); imp1 = new Duplicator().run(stackImp, frame, frame); try { if(beads == 0) IJ.saveAsTiff(imp1, folder_cell + "CorrBeadsAfter" + File.separator + "CorrBeadsAfter_" + IJ.pad(frame, 2) + ".tif"); else IJ.saveAsTiff(imp1, folder_cell + "CorrBeadsAfter_" + bead + File.separator + "CorrBeadsAfter_" + bead + "_" + IJ.pad(frame, 2) + ".tif"); // IJ.run("Close"); imp1.close(); } catch (Exception e) { if(beads == 0) showDialogWithImageAndCustomOkAndNoCancel("Traction force alignment make", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "CorrBeadsAfter" + File.separator + "CorrBeadsAfter_" + IJ.pad(frame, 2) + ".tif", "The analysis is stopped at the step \"Traction force alignment make\""); else showDialogWithImageAndCustomOkAndNoCancel("Traction force alignment make", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "CorrBeadsAfter_" + bead + File.separator + "CorrBeadsAfter_" + bead + "_" + IJ.pad(frame, 2) + ".tif", "The analysis is stopped at the step \"Traction force alignment make\""); return; } } // IJ.run("Close"); stackImp.close(); // croping and saving the beads reference image imp1 = null; if(beads == 0) imp1 = IJ.openImage(folder_cell + "Analysis" + File.separator + "CorrBeadsReference.tif"); else imp1 = IJ.openImage(folder_cell + "Analysis_" + bead + File.separator + "CorrBeadsReference_" + bead + ".tif"); if(imp1 == null) { if(!error) { error = true; if(beads == 0) showDialogWithImageAndCustomOkAndNoCancel("Traction force alignment crop", "undo.png", "The following file:\n\t\n" + folder_cell + "Analysis" + File.separator + "CorrBeadsReference.tif\n\t\ncould not be found" , "The analysis is stopped at the step \"Traction force alignment crop\""); else showDialogWithImageAndCustomOkAndNoCancel("Traction force alignment crop", "undo.png", "The following file:\n\t\n" + folder_cell + "Analysis_" + bead + File.separator + "CorrBeadsReference_" + bead + ".tif\n\t\ncould not be found", "The analysis is stopped at the step \"Traction force alignment crop\""); } return; } imp1.setRoi((int) x, (int) y, (int) width, (int) height); ip1 = imp1.getProcessor(); ip2 = ip1 .crop(); imp1.setProcessor(ip2); // Images cleaning - code from Mickael Schmid // IJ.run(imp1, "Thresholded Blur", "radius=3 threshold=1000 softness=0.50 strength=1"); // IJ.run(imp1, "Subtract Background...", "rolling=0.2 sliding"); try { if(beads == 0) IJ .saveAs(imp1, "Tiff", folder_cell + "Analysis" + File.separator + "CorrBeadsReference.tif"); else IJ .saveAs(imp1, "Tiff", folder_cell + "Analysis_" + bead + File.separator + "CorrBeadsReference_" + bead + ".tif"); imp1.close(); } catch (Exception e) { if(beads == 0) showDialogWithImageAndCustomOkAndNoCancel("Traction force alignment make", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "Analysis" + File.separator + "CorrBeadsReference.tif" , "The analysis is stopped at the step \"Traction force alignment make\""); else showDialogWithImageAndCustomOkAndNoCancel("Traction force alignment make", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "Analysis_" + bead + File.separator + "CorrBeadsReference_" + bead + ".tif", "The analysis is stopped at the step \"Traction force alignment make\""); return; } // croping and saving the Cells time images for(channel = 1; channel <= numberCh && channel != 0; channel++) { if((ch & 0x1) == 0 && (ch & 0x2) == 0 && (ch & 0x4) == 0) channel = 0; else if((ch & format[channel - 1]) == 0) continue; for(frame = frames_begin; frame <= frames; frame++) { imp1 = null; if(beads == 0) { switch (channel) { case 0: imp1 = IJ.openImage(folder_cell + "CorrCells" + File.separator + "CorrCells_" + IJ.pad(frame, 2) + ".tif"); break; case 1: imp1 = IJ.openImage(folder_cell + "CorrCells" + File.separator + "CorrCells_Ch1_" + IJ.pad(frame, 2) + ".tif"); break; case 2: imp1 = IJ.openImage(folder_cell + "CorrCells" + File.separator + "CorrCells_Ch2_" + IJ.pad(frame, 2) + ".tif"); break; case 3: imp1 = IJ.openImage(folder_cell + "CorrCells" + File.separator + "CorrCells_Ch3_" + IJ.pad(frame, 2) + ".tif"); break; } } else { // imp1 = IJ.openImage(folder_cell + "CorrCells_" + bead + File.separator + "CorrCells_" + bead + "_" + IJ.pad(frame, 2) + ".tif"); switch (channel) { case 0: imp1 = IJ.openImage(folder_cell + "CorrCells_" + bead + File.separator + "CorrCells_" + bead + "_" + IJ.pad(frame, 2) + ".tif"); break; case 1: imp1 = IJ.openImage(folder_cell + "CorrCells_" + bead + File.separator + "CorrCells_" + bead + "_Ch1_" + IJ.pad(frame, 2) + ".tif"); break; case 2: imp1 = IJ.openImage(folder_cell + "CorrCells_" + bead + File.separator + "CorrCells_" + bead + "_Ch2_" + IJ.pad(frame, 2) + ".tif"); break; case 3: imp1 = IJ.openImage(folder_cell + "CorrCells_" + bead + File.separator + "CorrCells_" + bead + "_Ch3_" + IJ.pad(frame, 2) + ".tif"); break; } } if(imp1 == null) { if(!error) { error = true; if(beads == 0) { switch (channel) { case 0: showDialogWithImageAndCustomOkAndNoCancel("Traction force alignment crop", "undo.png", "The following file:\n\t\n" + folder_cell + "CorrCells" + File.separator + "CorrCells_" + IJ.pad(frame, 2) + ".tif\n\t\ncould not be found", "The analysis is stopped at the step \"Traction force alignment crop\""); break; case 1: showDialogWithImageAndCustomOkAndNoCancel("Traction force alignment crop", "undo.png", "The following file:\n\t\n" + folder_cell + "CorrCells" + File.separator + "CorrCells_Ch1_" + IJ.pad(frame, 2) + ".tif\n\t\ncould not be found", "The analysis is stopped at the step \"Traction force alignment crop\""); break; case 2: showDialogWithImageAndCustomOkAndNoCancel("Traction force alignment crop", "undo.png", "The following file:\n\t\n" + folder_cell + "CorrCells" + File.separator + "CorrCells_Ch2_" + IJ.pad(frame, 2) + ".tif\n\t\ncould not be found", "The analysis is stopped at the step \"Traction force alignment crop\""); break; case 3: showDialogWithImageAndCustomOkAndNoCancel("Traction force alignment crop", "undo.png", "The following file:\n\t\n" + folder_cell + "CorrCells" + File.separator + "CorrCells_Ch3_" + IJ.pad(frame, 2) + ".tif\n\t\ncould not be found", "The analysis is stopped at the step \"Traction force alignment crop\""); break; } } else { switch (channel) { case 0: showDialogWithImageAndCustomOkAndNoCancel("Traction force alignment crop", "undo.png", "The following file:\n\t\n" + folder_cell + "CorrCells_" + bead + File.separator + "CorrCells_" + bead + "_" + IJ.pad(frame, 2) + ".tif\n\t\ncould not be found", "The analysis is stopped at the step \"Traction force alignment crop\""); break; case 1: showDialogWithImageAndCustomOkAndNoCancel("Traction force alignment crop", "undo.png", "The following file:\n\t\n" + folder_cell + "CorrCells_" + bead + File.separator + "CorrCells_" + bead + "_Ch1_" + IJ.pad(frame, 2) + ".tif\n\t\ncould not be found", "The analysis is stopped at the step \"Traction force alignment crop\""); break; case 2: showDialogWithImageAndCustomOkAndNoCancel("Traction force alignment crop", "undo.png", "The following file:\n\t\n" + folder_cell + "CorrCells_" + bead + File.separator + "CorrCells_" + bead + "_Ch2_" + IJ.pad(frame, 2) + ".tif\n\t\ncould not be found", "The analysis is stopped at the step \"Traction force alignment crop\""); break; case 3: showDialogWithImageAndCustomOkAndNoCancel("Traction force alignment crop", "undo.png", "The following file:\n\t\n" + folder_cell + "CorrCells_" + bead + File.separator + "CorrCells_" + bead + "_Ch3_" + IJ.pad(frame, 2) + ".tif\n\t\ncould not be found", "The analysis is stopped at the step \"Traction force alignment crop\""); break; } } } return; } imp1.setRoi((int) x, (int) y, (int) width, (int) height); ip1 = imp1.getProcessor(); ip2 = ip1 .crop(); imp1.setProcessor(ip2); try { if(beads == 0) { // IJ .saveAs(imp1, "Tiff", folder_cell + "CorrCells" + File.separator + "CorrCells_" + IJ.pad(frame, 2) + ".tif"); switch (channel) { case 0: IJ.saveAsTiff(imp1, folder_cell + "CorrCells" + File.separator + "CorrCells_" + IJ.pad(frame, 2) + ".tif"); break; case 1: IJ.saveAsTiff(imp1, folder_cell + "CorrCells" + File.separator + "CorrCells_Ch1_" + IJ.pad(frame, 2) + ".tif"); break; case 2: IJ.saveAsTiff(imp1, folder_cell + "CorrCells" + File.separator + "CorrCells_Ch2_" + IJ.pad(frame, 2) + ".tif"); break; case 3: IJ.saveAsTiff(imp1, folder_cell + "CorrCells" + File.separator + "CorrCells_Ch3_" + IJ.pad(frame, 2) + ".tif"); break; } } else { // IJ .saveAs(imp1, "Tiff", folder_cell + "CorrCells_" + bead + File.separator + "CorrCells_" + bead + "_" + IJ.pad(frame, 2) + ".tif"); switch (channel) { case 0: IJ.saveAsTiff(imp1, folder_cell + "CorrCells_" + bead + File.separator + "CorrCells_" + bead + "_" + IJ.pad(frame, 2) + ".tif"); break; case 1: IJ.saveAsTiff(imp1, folder_cell + "CorrCells_" + bead + File.separator + "CorrCells_" + bead + "_Ch1_" + IJ.pad(frame, 2) + ".tif"); break; case 2: IJ.saveAsTiff(imp1, folder_cell + "CorrCells_" + bead + File.separator + "CorrCells_" + bead + "_Ch2_" + IJ.pad(frame, 2) + ".tif"); break; case 3: IJ.saveAsTiff(imp1, folder_cell + "CorrCells_" + bead + File.separator + "CorrCells_" + bead + "_Ch3_" + IJ.pad(frame, 2) + ".tif"); break; } } imp1.close(); } catch (Exception e) { if(beads == 0) { switch (channel) { case 0: showDialogWithImageAndCustomOkAndNoCancel("Traction force alignment crop", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "CorrCells" + File.separator + "CorrCells_" + IJ.pad(frame, 2) + ".tif", "The analysis is stopped at the step \"Traction force alignment crop\""); break; case 1: showDialogWithImageAndCustomOkAndNoCancel("Traction force alignment crop", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "CorrCells" + File.separator + "CorrCells_Ch1_" + IJ.pad(frame, 2) + ".tif", "The analysis is stopped at the step \"Traction force alignment crop\""); break; case 2: showDialogWithImageAndCustomOkAndNoCancel("Traction force alignment crop", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "CorrCells" + File.separator + "CorrCells_Ch2_" + IJ.pad(frame, 2) + ".tif", "The analysis is stopped at the step \"Traction force alignment crop\""); break; case 3: showDialogWithImageAndCustomOkAndNoCancel("Traction force alignment crop", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "CorrCells" + File.separator + "CorrCells_Ch3_" + IJ.pad(frame, 2) + ".tif", "The analysis is stopped at the step \"Traction force alignment crop\""); break; } } else { switch (channel) { case 0: showDialogWithImageAndCustomOkAndNoCancel("Traction force alignment crop", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "CorrCells_" + bead + File.separator + "CorrCells_" + bead + "_" + IJ.pad(frame, 2) + ".tif", "The analysis is stopped at the step \"Traction force alignment crop\""); break; case 1: showDialogWithImageAndCustomOkAndNoCancel("Traction force alignment crop", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "CorrCells_" + bead + File.separator + "CorrCells_" + bead + "_Ch1_" + IJ.pad(frame, 2) + ".tif", "The analysis is stopped at the step \"Traction force alignment crop\""); break; case 2: showDialogWithImageAndCustomOkAndNoCancel("Traction force alignment crop", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "CorrCells_" + bead + File.separator + "CorrCells_" + bead + "_Ch2_" + IJ.pad(frame, 2) + ".tif", "The analysis is stopped at the step \"Traction force alignment crop\""); break; case 3: showDialogWithImageAndCustomOkAndNoCancel("Traction force alignment crop", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "CorrCells_" + bead + File.separator + "CorrCells_" + bead + "_Ch3_" + IJ.pad(frame, 2) + ".tif", "The analysis is stopped at the step \"Traction force alignment crop\""); break; } } return; } } if((ch & 0x1) == 0 && (ch & 0x2) == 0 && (ch & 0x4) == 0) channel--; } // updating and saving "JEasyTFM_x_end.txt" file if((bead == 0 || bead == 2) && traction_folder == traction_ending_folder) { traction_force_alignment = false; traction_force_alignment_crop = false; saveJob(folder + "Jobs" + File.separator + "JEasyTFM_" + job_index + "_end.txt"); } /////////////////////////////////////////////////// } // traction_force_alignment_crop } // traction_force_alignment if(traction_force_calculation) { if(piv_calculation) { for(frame = frames_begin; frame <= frames; frame++) { imp1 = imp2 = null; // Force 0 if(beads == 0) { imp1 = IJ.openImage(folder_cell + "Analysis" + File.separator + "CorrBeadsReference.tif"); if(imp1 == null) { if(!error) { error = true; showDialogWithImageAndCustomOkAndNoCancel("PIV calculation", "undo.png", "The following file:\n\t\n" + folder_cell + "Analysis" + File.separator + "CorrBeadsReference.tif\n\t\ncould not be found", "The analysis is stopped at the step \"PIV calculation\""); } return; } is = imp1.getStack(); imp2 = IJ.openImage(folder_cell + "CorrBeadsAfter" + File.separator + "CorrBeadsAfter_" + IJ.pad(frame, 2) + ".tif"); if(imp2 == null) { if(!error) { error = true; showDialogWithImageAndCustomOkAndNoCancel("PIV calculation", "undo.png", "The following file:\n\t\n" + folder_cell + "CorrBeadsAfter" + File.separator + "CorrBeadsAfter_" + IJ.pad(frame, 2) + ".tif\n\t\ncould not be found", "The analysis is stopped at the step \"PIV calculation\""); } imp1.close(); return; } ip2 = imp2.getProcessor(); is .addSlice(ip2); stackImp= new ImagePlus("Stack_" + IJ.pad(frame, 2) + ".tif", is); } else { imp1 = IJ.openImage(folder_cell + "Analysis_" + bead + File.separator + "CorrBeadsReference_" + bead + ".tif"); if(imp1 == null) { if(!error) { error = true; showDialogWithImageAndCustomOkAndNoCancel("PIV calculation", "undo.png", "The following file:\n\t\n" + folder_cell + "Analysis_" + bead + File.separator + "CorrBeadsReference_" + bead + ".tif\n\t\ncould not be found" , "The analysis is stopped at the step \"PIV calculation\""); } return; } is = imp1.getStack(); imp2 = IJ.openImage(folder_cell + "CorrBeadsAfter_" + bead + File.separator + "CorrBeadsAfter_" + bead + "_" + IJ.pad(frame, 2) + ".tif"); if(imp2 == null) { if(!error) { error = true; showDialogWithImageAndCustomOkAndNoCancel("PIV calculation", "undo.png", "The following file:\n\t\n" + folder_cell + "CorrBeadsAfter_" + bead + File.separator + "CorrBeadsAfter_" + bead + "_" + IJ.pad(frame, 2) + ".tif\n\t\ncould not be found", "The analysis is stopped at the step \"PIV calculation\""); } imp1.close(); return; } ip2 = imp2.getProcessor(); is .addSlice(ip2); stackImp= new ImagePlus("Stack_" + bead + "_" + IJ.pad(frame, 2) + ".tif", is); } // IJ.run("Images to Stack", "name=Stack title=[] use"); // IJ.run("Translation Alignment"); // IJ.saveAs("Tiff", folder_cell + "Stack" + IJ.pad(frame, 2) + ".tif"); // IJ.selectWindow("Stack" + IJ.pad(frame, 2) + ".tif"); // Force 1 converter = new ImageConverter(stackImp); converter .convertToGray16(); if(debug) { stackImp .show(); // IJ.run("Reverse"); if(beads == 0) IJ.run(stackImp, "PIV Advanced", " piv1=128 sw1=256 vs1=64 piv2=64 sw2=128 vs2=32 piv3=48 sw3=128 vs3=&vs3 correlation=0.60 debug_x=-1 debug_y=-1 path=/ what=[Normalized median test and replace invalid by median then Accept this PIV and output] noise=0.20 threshold=5 c1=3 c2=1 save=[" + folder_cell + "Analysis" + File.separator + "Stack_" + IJ.pad(frame, 2) + ".txt]"); else IJ.run(stackImp, "PIV Advanced", " piv1=128 sw1=256 vs1=64 piv2=64 sw2=128 vs2=32 piv3=48 sw3=128 vs3=&vs3 correlation=0.60 debug_x=-1 debug_y=-1 path=/ what=[Normalized median test and replace invalid by median then Accept this PIV and output] noise=0.20 threshold=5 c1=3 c2=1 save=[" + folder_cell + "Analysis_" + bead + File.separator + "Stack_" + bead + "_" + IJ.pad(frame, 2) + ".txt]"); IJ.run("Close"); if(beads == 0) { // IJ.selectWindow("PIV3_" + "Stack_" + IJ.pad(frame, 2) + ".tif"); // IJ.saveAs("Tiff", folder_cell + "PIV3_" + "Stack_" + IJ.pad(frame, 2) + ".tif"); // IJ.run("Close"); closeWindow("PIV3_" + "Stack_" + IJ.pad(frame, 2) + ".tif"); closeWindow("PIV2_" + "Stack_" + IJ.pad(frame, 2) + ".tif"); closeWindow("PIV1_" + "Stack_" + IJ.pad(frame, 2) + ".tif"); closeWindow( "Stack_" + IJ.pad(frame, 2) + ".tif"); } else { // IJ.selectWindow("PIV3_" + "Stack_" + bead + "_" + IJ.pad(frame, 2) + ".tif"); // IJ.saveAs("Tiff", folder_cell + "PIV3_" + "Stack_" + bead + "_" + IJ.pad(frame, 2) + ".tif"); // IJ.run("Close"); closeWindow("PIV3_" + "Stack_" + bead + "_" + IJ.pad(frame, 2) + ".tif"); closeWindow("PIV2_" + "Stack_" + bead + "_" + IJ.pad(frame, 2) + ".tif"); closeWindow("PIV1_" + "Stack_" + bead + "_" + IJ.pad(frame, 2) + ".tif"); closeWindow( "Stack_" + bead + "_" + IJ.pad(frame, 2) + ".tif"); } } else { if(beads == 0) PIV_iterative.generateAdvancedIterativePIV(stackImp, false, 128, 256, 64, 64, 128, 32, 48, 128, 16, 0.60, false, false, false, false, "", "Normalized median test and replace invalid by median then Accept this PIV and output", 0.20, 5, 3, 1, folder_cell + "Analysis" + File.separator + "Stack_" + IJ.pad(frame, 2) + ".txt"); else PIV_iterative.generateAdvancedIterativePIV(stackImp, false, 128, 256, 64, 64, 128, 32, 48, 128, 16, 0.60, false, false, false, false, "", "Normalized median test and replace invalid by median then Accept this PIV and output", 0.20, 5, 3, 1, folder_cell + "Analysis_" + bead + File.separator + "Stack_" + bead + "_" + IJ.pad(frame, 2) + ".txt"); } imp1 .close(); imp2 .close(); stackImp.changes = false; stackImp.close(); closeWindows(); try { if(beads == 0) { PIV_plot.drawPlot(folder_cell + "Analysis" + File.separator, "Stack_" + IJ.pad(frame, 2) + ".txt", true, 1, 50.0, 0, 0, false, false, false, true, false, false, lut); IJ.saveAs("Tiff", folder_cell + "Analysis" + File.separator + "PIV3_Stack_" + IJ.pad(frame, 2) + ".tif"); } else { PIV_plot.drawPlot(folder_cell + "Analysis_" + bead + File.separator, "Stack_" + bead + "_" + IJ.pad(frame, 2) + ".txt", true, 1, 50.0, 0, 0, false, false, false, true, false, false, lut); IJ.saveAs("Tiff", folder_cell + "Analysis_" + bead + File.separator + "PIV3_Stack_" + bead + "_" + IJ.pad(frame, 2) + ".tif"); } IJ.run("Close"); } catch (Exception e) { if (beads == 0) showDialogWithImageAndCustomOkAndNoCancel("PIV calculation", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "Analysis" + File.separator + "PIV3_Stack_" + IJ.pad(frame, 2) + ".tif", "The analysis is stopped at the step \"PIV calculation\""); else showDialogWithImageAndCustomOkAndNoCancel("PIV calculation", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "Analysis_" + bead + File.separator + "PIV3_Stack_" + bead + "_" + IJ.pad(frame, 2) + ".tif", "The analysis is stopped at the step \"PIV calculation\""); return; } } // updating and saving "JEasyTFM_x_end.txt" file if((bead == 0 || bead == 2) && traction_folder == traction_ending_folder) { piv_calculation = false; saveJob(folder + "Jobs" + File.separator + "JEasyTFM_" + job_index + "_end.txt"); } /////////////////////////////////////////////////// } // piv_calculation if(lambda_calculation) { try { if(beads == 0) { checkAndCreateFolder( folder_cell + "Analysis"); IJ.saveString ("Stack\tLambda\n" , folder_cell + "Analysis" + File.separator + "Lambda.txt"); } else { checkAndCreateFolder( folder_cell + "Analysis_" + bead); IJ.saveString ("Stack\tLambda\n" , folder_cell + "Analysis_" + bead + File.separator + "Lambda.txt"); } } catch (Exception e) { if(beads == 0) showDialogWithImageAndCustomOkAndNoCancel("Lambda value calculation", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "Analysis" + File.separator + "Lambda.txt", "The analysis is stopped at the step \"Traction force Lambda calculation\""); else showDialogWithImageAndCustomOkAndNoCancel("Lambda value calculation", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "Analysis_" + bead + File.separator + "Lambda.txt", "The analysis is stopped at the step \"Traction force Lambda calculation\""); return; } lambda_values = new double[frames]; for(frame = frames_begin; frame <= frames; frame++) { // frame = 1; /* debut double min = FTTC_main.getScaleValue(folder_cell + "Analysis" + File.separator, "Stack_" + IJ.pad(frame, 2) + ".txt", length_scale, 0.5, E, 1.0e1 , unitIndex, widthCorr, heightCorr, false, false, false, false, false, false, lut); double max = FTTC_main.getScaleValue(folder_cell + "Analysis" + File.separator, "Stack_" + IJ.pad(frame, 2) + ".txt", length_scale, 0.5, E, 1.0e-21, unitIndex, widthCorr, heightCorr, false, false, false, false, false, false, lut); double goal = (max - min) / 2.0; IJ.log("min = " + min); IJ.log("max = " + max); IJ.log("precisionForLambda = " + precisionForLambda); IJ.log("goal = " + goal); fin */ // lambda = Math.pow(10.0, -runBinarySearch(-1, 21, precisionForLambda, folder_cell, frame, widthCorr, heightCorr)); lambda_values[frame - 1] = Math.pow(10.0, -runBinarySearch(-1, 21, precisionForLambda, folder_cell, frame, widthCorr, heightCorr)); // IJ.log("output = " + FTTC_main.getScaleValue(folder_cell + "Analysis" + File.separator, "Stack_" + IJ.pad(frame, 2) + ".txt", length_scale, 0.5, E, lambda, unitIndex, widthCorr, heightCorr, false, false, false, false, false, false, lut)); try { if(beads == 0) IJ.append("Stack_" + IJ.pad(frame, 2) + "\t" + lambda_values[frame - 1] , folder_cell + "Analysis" + File.separator + "Lambda.txt"); else IJ.append("Stack_" + IJ.pad(frame, 2) + "\t" + lambda_values[frame - 1] , folder_cell + "Analysis_" + bead + File.separator + "Lambda.txt"); } catch (Exception e) { if(beads == 0) showDialogWithImageAndCustomOkAndNoCancel("Lambda value calculation", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "Analysis" + File.separator + "Lambda.txt", "The analysis is stopped at the step \"Traction force Lambda calculation\""); else showDialogWithImageAndCustomOkAndNoCancel("Lambda value calculation", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "Analysis_" + bead + File.separator + "Lambda.txt", "The analysis is stopped at the step \"Traction force Lambda calculation\""); return; } } } // lambda_calculation if(force_calculation) { // In the case the lamda values haven't been generated they can be read from the Lambda.txt file if(lambda_values == null) { if(beads == 0) lambda_values = get_lambda_values(folder_cell + "Analysis" + File.separator + "Lambda.txt"); else lambda_values = get_lambda_values(folder_cell + "Analysis_" + bead + File.separator + "Lambda.txt"); } for(frame = frames_begin; frame <= frames; frame++) { // Force 2 if(beads == 0) { file = new File(folder_cell + "Analysis" + File.separator + "Stack_" + IJ.pad(frame, 2) + ".txt"); if (!file.exists()) { showDialogWithImageAndCustomOkAndNoCancel("Force calculation", "undo.png", "The following file:\n\t\n" + folder_cell + "Analysis" + File.separator + "Stack_" + IJ.pad(frame, 2) + ".txt\n\t\ncould not be found", "The analysis is stopped at the step \"Force calculation\""); return; } else { try { scale[frame - 1] = FTTC_main.getScaleValue(folder_cell + "Analysis" + File.separator, "Stack_" + IJ.pad(frame, 2) + ".txt", length_scale, 0.5, E, lambda_values[frame - 1], unitIndex, widthCorr, heightCorr, false, false, false, false, false, false, lut); } catch (Exception e) { showDialogWithImageAndCustomOkAndNoCancel("Force calculation", "calculator.png", "Error while calculating\n \n" + e.getMessage() + "\n \n" + folder_cell + "Analysis" + File.separator + "Stack_" + IJ.pad(frame, 2) + ".txt", "The analysis is stopped at the step \"Force calculation\""); return; } } } else { file = new File(folder_cell + "Analysis_" + bead + File.separator + "Stack_" + bead + "_" + IJ.pad(frame, 2) + ".txt"); if (!file.exists()) { showDialogWithImageAndCustomOkAndNoCancel("Force calculation", "undo.png", "The following file:\n\t\n" + folder_cell + "Analysis_" + bead + File.separator + "Stack_" + bead + "_" + IJ.pad(frame, 2) + ".txt\n\t\ncould not be found", "The analysis is stopped at the step \"Force calculation\""); return; } else { try { scale[frame - 1] = FTTC_main.getScaleValue(folder_cell + "Analysis_" + bead + File.separator, "Stack_" + bead + "_" + IJ.pad(frame, 2) + ".txt", length_scale, 0.5, E, lambda_values[frame - 1], unitIndex, widthCorr, heightCorr, false, false, false, false, false, false, lut); } catch (Exception e) { showDialogWithImageAndCustomOkAndNoCancel("Force calculation", "calculator.png", "Error while calculating\n \n" + e.getMessage() + "\n \n" + folder_cell + "Analysis_" + bead + File.separator + "Stack_" + bead + "_" + IJ.pad(frame, 2) + ".txt", "The analysis is stopped at the step \"Force calculation\""); } } } } // Array.getStatistics(Scale, Scalemin, Scalemax, Scalemean, ScalestdDev); scaleMin = scaleMax = scale[0]; for(frame = 1; frame < scale.length; frame++) { if(scale[frame] > scaleMax) scaleMax = scale[frame]; else if (scale[frame] < scaleMin) scaleMin = scale[frame]; } if(debug) IJ.log("Scale " + scaleMin + " " + scaleMax); try { if(beads == 0) fos = new FileOutputStream (folder_cell + "Analysis" + File.separator + "scale.txt"); else fos = new FileOutputStream (folder_cell + "Analysis_" + bead + File.separator + "scale_" + bead + ".txt"); bos = new BufferedOutputStream (fos); writer = new PrintWriter (bos, true); if(beads == 0) { for(frame = 1; frame < scale.length; frame++) writer .println("Stack_" + IJ.pad(frame, 2) + "\t" + String.valueOf(scale[frame - 1])); } else { for(frame = 1; frame < scale.length; frame++) writer .println("Stack_" + bead + "_" + IJ.pad(frame, 2) + "\t" + String.valueOf(scale[frame - 1])); } writer .println("Scale " + scaleMin + " " + scaleMax); writer .close(); } catch (IOException e) { if(beads == 0) showDialogWithImageAndCustomOkAndNoCancel("Force calculation", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "Analysis" + File.separator + "scale.txt" , "The analysis is stopped at the step \"Force calculation\""); else showDialogWithImageAndCustomOkAndNoCancel("Force calculation", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "Analysis_" + bead + File.separator + "scale_" + bead + ".txt", "The analysis is stopped at the step \"Force calculation\""); return; } // Force 3 if(beads == 0) checkAndCreateFolder(folder_cell + "Traction_Vector_Plot"); else checkAndCreateFolder(folder_cell + "Traction_Vector_Plot_" + bead); for(frame = frames_begin; frame <= frames; frame++) { if(beads == 0) { file = new File(folder_cell + "Analysis" + File.separator + "Traction_Stack_" + IJ.pad(frame, 2) + ".txt"); if (!file.exists()) { showDialogWithImageAndCustomOkAndNoCancel("Force calculation", "undo.png", "The following file:\n\t\n" + folder_cell + "Analysis" + File.separator + "Traction_Stack_" + IJ.pad(frame, 2) + ".txt\n\t\ncould not be found", "The analysis is stopped at the step \"Force calculation\""); return; } else { try { FTTC_plot.drawPlot(folder_cell + "Analysis" + File.separator , "Traction_Stack_" + IJ.pad(frame, 2) + ".txt", FTTC_max_vector_length, niceNumber(scaleMax), niceNumber(scaleMax * window_area), unitIndex, widthCorr, heightCorr, false, true, true, false, false, false, lut); } catch (Exception e) { showDialogWithImageAndCustomOkAndNoCancel("Force calculation", "calculator.png", "Error while calculating\n \n" + e.getMessage() + "\n \n" + folder_cell + "Analysis" + File.separator + "Traction_Stack_" + IJ.pad(frame, 2) + ".txt", "The analysis is stopped at the step \"Force calculation\""); return; } } imp1 = IJ.getImage(); try { IJ.saveAsTiff(imp1, folder_cell + "Traction_Vector_Plot" + File.separator + "Traction_Magnitude_Plot_Traction_Stack_" + IJ.pad(frame, 2) + ".tif"); } catch (Exception e) { showDialogWithImageAndCustomOkAndNoCancel("force_integration", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "Traction_Vector_Plot" + File.separator + "Traction_Magnitude_Plot_Traction_Stack_" + IJ.pad(frame, 2) + ".tif", "The analysis is stopped at the step \"force_integration\""); return; } imp1.close(); imp2 = IJ.getImage(); try { IJ.saveAsTiff(imp2, folder_cell + "Traction_Vector_Plot" + File.separator + "Traction_Vector_Plot_Traction_Stack_" + IJ.pad(frame, 2) + ".tif"); } catch (Exception e) { showDialogWithImageAndCustomOkAndNoCancel("force_integration", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "Traction_Vector_Plot" + File.separator + "Traction_Vector_Plot_Traction_Stack_" + IJ.pad(frame, 2) + ".tif", "The analysis is stopped at the step \"force_integration\""); return; } imp2.close(); } else { file = new File(folder_cell + "Analysis_" + bead + File.separator + "Traction_Stack_" + bead + "_" + IJ.pad(frame, 2) + ".txt"); if (!file.exists()) { showDialogWithImageAndCustomOkAndNoCancel("Force calculation", "undo.png", "The following file:\n\t\n" + folder_cell + "Analysis_" + bead + File.separator + "Traction_Stack_" + bead + "_" + IJ.pad(frame, 2) + ".txt\n\t\ncould not be found", "The analysis is stopped at the step \"Force calculation\""); return; } else { try { FTTC_plot.drawPlot(folder_cell + "Analysis_" + bead + File.separator, "Traction_Stack_" + bead + "_" + IJ.pad(frame, 2) + ".txt", FTTC_max_vector_length, niceNumber(scaleMax), niceNumber(scaleMax * window_area), unitIndex, widthCorr, heightCorr, false, true, true, false, false, false, lut); } catch (Exception e) { showDialogWithImageAndCustomOkAndNoCancel("Force calculation", "calculator.png", "Error while calculating\n \n" + e.getMessage() + "\n \n" + folder_cell + "Analysis_" + bead + File.separator + "Traction_Stack_" + bead + "_" + IJ.pad(frame, 2) + ".txt", "The analysis is stopped at the step \"Force calculation\""); return; } } imp1 = IJ.getImage(); try { IJ.saveAsTiff(imp1, folder_cell + "Traction_Vector_Plot_" + bead + File.separator + "Traction_Magnitude_Plot_Traction_Stack_" + bead + "_" + IJ.pad(frame, 2) + ".tif"); } catch (Exception e) { showDialogWithImageAndCustomOkAndNoCancel("force_integration", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "Traction_Vector_Plot_" + bead + File.separator + "Traction_Magnitude_Plot_Traction_Stack_" + bead + "_" + IJ.pad(frame, 2) + ".tif", "The analysis is stopped at the step \"force_integration\""); return; } imp1.close(); imp2 = IJ.getImage(); try { IJ.saveAsTiff(imp2, folder_cell + "Traction_Vector_Plot_" + bead + File.separator + "Traction_Vector_Plot_Traction_Stack_" + bead + "_" + IJ.pad(frame, 2) + ".tif"); } catch (Exception e) { showDialogWithImageAndCustomOkAndNoCancel("force_integration", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "Traction_Vector_Plot_" + bead + File.separator + "Traction_Vector_Plot_Traction_Stack_" + bead + "_" + IJ.pad(frame, 2) + ".tif", "The analysis is stopped at the step \"force_integration\""); return; } imp2.close(); try { IJ.saveAs("Tiff", folder_cell + "Traction_Vector_Plot_" + bead + File.separator + "Traction_Vector_Plot_Traction_Stack_" + bead + "_" + IJ.pad(frame, 2) + ".tif"); } catch (Exception e) { showDialogWithImageAndCustomOkAndNoCancel("Force calculation", "write.png", "Error while saving\n \n" + e.getMessage() + "\n \n" + folder_cell + "Traction_Vector_Plot_" + bead + File.separator + "Traction_Vector_Plot_Traction_Stack_" + bead + "_" + IJ.pad(frame, 2) + ".tif", "The analysis is stopped at the step \"Force calculation\""); return; } } // IJ.run("Close"); // closeWindows(); } // updating and saving "JEasyTFM_x_end.txt" file if((bead == 0 || bead == 2) && traction_folder == traction_ending_folder) { traction_force_calculation = false; force_calculation = false; saveJob(folder + "Jobs" + File.separator + "JEasyTFM_" + job_index + "_end.txt"); } /////////////////////////////////////////////////// } // force_calculation if(force_superposition) { // Force 4 if(beads == 0) checkAndCreateFolder(folder_cell + "PicCells"); else checkAndCreateFolder(folder_cell + "PicCells_" + bead); for(channel = 1; channel <= numberCh && channel != 0; channel++) { if((ch & 0x1) == 0 && (ch & 0x2) == 0 && (ch & 0x4) == 0) channel = 0; else if((ch & format[channel - 1]) == 0) continue; for(frame = frames_begin; frame <= frames; frame++) { cellsAndForceImagesSuperposition(channel, traction_folder, bead, frame, folder_cell, "Traction_Vector_Plot", "PicCells", "Superposition", "Vector" , Blitter.COPY_ZERO_TRANSPARENT, false, Double.NaN); cellsAndForceImagesSuperposition(channel, traction_folder, bead, frame, folder_cell, "Traction_Vector_Plot", "PicCells", "Superposition", "Magnitude", Blitter.ADD , false, Double.NaN); } if((ch & 0x1) == 0 && (ch & 0x2) == 0 && (ch & 0x4) == 0) channel--; } Roi.setPasteMode(Blitter.COPY); // updating and saving "JEasyTFM_x_end.txt" file if((bead == 0 || bead == 2) && traction_folder == traction_ending_folder) { force_superposition = false; force_calculation = false; saveJob(folder + "Jobs" + File.separator + "JEasyTFM_" + job_index + "_end.txt"); } /////////////////////////////////////////////////// } // force_superposition } // traction_force_calculation // updating and saving "JEasyTFM_x_end.txt" file if(bead == 0 || bead == 2) { if(traction_starting_folder < traction_ending_folder) traction_starting_folder++; else { traction_force = false; traction_starting_folder = 1; } saveJob(folder + "Jobs" + File.separator + "JEasyTFM_" + job_index + "_end.txt"); } /////////////////////////////////////////////////// } if(beads == 0) bead--; } // traction_force_calculation } // traction_force private void cells_analysis() { boolean generate_scale = true; // double regularization_factor = lambda; // double regularization_factor = 1e-10; // !!! Different from the lambda used in the rest of the analysis // double regularization_factor = 0; // DecimalFormat decimalFormat1 = new DecimalFormat("#0.00000"); // DecimalFormat decimalFormat2 = new DecimalFormat("#0.00"); // DecimalFormat decimalFormat3 = new DecimalFormat("0.00E0"); ImagePlus imp0, imp1, imp2, imp3, imp4, imp5; ImageConverter converter; ImageCalculator ic; Color color; ResultsTable rt; // Roi roi; RoiManager rm; WaitForUserDialog waitForUserDialog; String folder_cell; String Name; String str; String [] lines, columns; int cells_analysis_folder, bead, channel, frame, slice; int roi_x, roi_y; int roi_width = 0; int roi_height = 0; int width, height; // int channels, slices, frames; int [] dim; double [] shift_x, shift_y; int widthCorr = 0; int heightCorr = 0; // int area, force; double scaleMin; double scaleMax; // int [] delta, dim; double [] scale; imp2 = null; imp5 = null; // for(bead = 1; bead <= format.length && bead != 0; bead++) for(bead = 1; bead <= 2 && bead != 0; bead++) { if(beads == 0) bead = 0; else if((beads & format[bead - 1]) == 0) continue; for(cells_analysis_folder = cells_analysis_starting_folder; cells_analysis_folder <= cells_analysis_ending_folder; cells_analysis_folder++) { folder_cell = folder + "Cell " + cells_analysis_folder + File.separator; if(cells_segmentation) { if(beads == 0) str = IJ.openAsString(folder_cell + "Analysis" + File.separator + "Transformation.txt"); else str = IJ.openAsString(folder_cell + "Analysis_" + bead + File.separator + "Transformation.txt"); if(str.startsWith("Error")) { if(!error) { error = true; if(beads == 0) showDialogWithImageAndCustomOkAndNoCancel("Cells segmentation", "undo.png", "The following file:\n\t\n" + folder_cell + "Analysis" + File.separator + "Transformation.txt\n\t\ncould not be opened and generated the following error message:\n \n\"" + str + "\"", "The analysis is stopped at the step \"Cells segmentation\""); else showDialogWithImageAndCustomOkAndNoCancel("Cells segmentation", "undo.png", "The following file:\n\t\n" + folder_cell + "Analysis_" + bead + File.separator + "Transformation.txt\n\t\ncould not be opened and generated the following error message:\n \n\"" + str + "\"", "The analysis is stopped at the step \"Cells segmentation\""); } return; } lines = split(str, "\n"); if(lines.length <= 3) { if(beads == 0) showDialogWithImageAndCustomOkAndNoCancel("Cells segmentation", "calculator.png", "The format of the data imported from the following file:\n \n" + folder_cell + "Analysis" + File.separator + "Transformation.txt\n \n\nare not correct!\n \nPlease check the content of the file.", "The analysis is stopped at the step \"Cells segmentation\""); else showDialogWithImageAndCustomOkAndNoCancel("Cells segmentation", "calculator.png", "The following file:\n\t\n" + folder_cell + "Analysis_" + bead + File.separator + "Transformation.txt\n \n\nare not correct!\n \nPlease check the content of the file.", "The analysis is stopped at the step \"Cells segmentation\""); return; } shift_x = new double[lines.length - 3]; shift_y = new double[lines.length - 3]; for (int line = 1; line < lines.length - 2; line++) { columns = split(lines[line], "\t"); shift_x[line - 1] = Double.valueOf(columns[1]); shift_y[line - 1] = Double.valueOf(columns[2]); } columns = split(lines[lines.length - 1], "\t"); roi_x = Integer.parseInt(columns[0]); roi_y = Integer.parseInt(columns[1]); roi_width = Integer.parseInt(columns[2]); roi_height = Integer.parseInt(columns[3]); Name = file1 + cells_analysis_folder + "_" + IJ.pad(2 * cells_analysis_folder - 1, 2); imp1 = imp2 = imp3 = null; imp1 = IJ.openImage(folder + file1 + cells_analysis_folder + "_" + IJ.pad(2 * cells_analysis_folder - 1, 2) + ".tif"); if(imp1 == null) imp1 = IJ.openImage(folder + file1 + cells_analysis_folder + "_" + IJ.pad(3 * cells_analysis_folder - 2, 2) + ".tif"); if(imp1 == null) { imp2 = IJ.openImage(folder + file1 + cells_analysis_folder + "_" + IJ.pad(2 * cells_analysis_folder - 1, 2) + "_p1.tif"); if(imp2 == null) { if(!error) { error = true; showDialogWithImageAndCustomOkAndNoCancel("Cells segmentation", "undo.png", "The following file:\n\t\n" + folder + file1 + cells_analysis_folder + "_" + IJ.pad(2 * cells_analysis_folder - 1, 2) + "_p1.tif\n\t\ncould not be found", "The analysis is stopped at the step \"Cells segmentation\""); } return; } imp3 = IJ.openImage(folder + file1 + cells_analysis_folder + "_" + IJ.pad(2 * cells_analysis_folder - 1, 2) + "_p2.tif"); if(imp3 == null) { if(!error) { error = true; showDialogWithImageAndCustomOkAndNoCancel("Cells segmentation", "undo.png", "The following file:\n\t\n" + folder + file1 + cells_analysis_folder + "_" + IJ.pad(2 * cells_analysis_folder - 1, 2) + "_p2.tif\n\t\ncould not be found", "The analysis is stopped at the step \"Cells segmentation\""); } imp2.close(); return; } imp1 = Concatenator.run(imp2, imp3); imp2 .close(); imp3 .close(); } if(imp1 == null) { imp2 = IJ.openImage(folder + file1 + cells_analysis_folder + "_" + IJ.pad(3 * cells_analysis_folder - 2, 2) + "_p1.tif"); if(imp2 == null) { if(!error) { error = true; showDialogWithImageAndCustomOkAndNoCancel("Cells segmentation", "undo.png", "The following file:\n\t\n" + folder + file1 + cells_analysis_folder + "_" + IJ.pad(3 * cells_analysis_folder - 2, 2) + "_p1.tif\n\t\ncould not be found", "The analysis is stopped at the step \"Cells segmentation\""); } imp1.close(); return; } imp3 = IJ.openImage(folder + file1 + cells_analysis_folder + "_" + IJ.pad(3 * cells_analysis_folder - 2, 2) + "_p2.tif"); if(imp3 == null) { if(!error) { error = true; showDialogWithImageAndCustomOkAndNoCancel("Cells segmentation", "undo.png", "The following file:\n\t\n" + folder + file1 + cells_analysis_folder + "_" + IJ.pad(3 * cells_analysis_folder - 2, 2) + "_p2.tif\n\t\ncould not be found", "The analysis is stopped at the step \"Cells segmentation\""); } imp1.close(); imp2.close(); return; } imp1 = Concatenator.run(imp2, imp3); imp2 .close(); imp3 .close(); } if(imp1.isHyperStack()) { frames = imp1.getNFrames(); slices = imp1.getNSlices(); } try { imp1 = HyperStackConverter.toHyperStack(imp1, 1, slices, frames, "default", "Grayscale"); } catch (Exception e) { showDialogWithImageAndCustomOkAndNoCancel("Cells segmentation", "calculator.png", "Error while trying to transform the stack image \n" + imp1.getTitle() + "\ncontaining " + imp1.getStackSize() + " pictures into an hyperStack of\nChannels 1\nSlices " + slices + "\nFrames " + frames + "\ni.e. " + slices * frames + " images" , "The analysis is stopped at the step \"Cells segmentation\""); return; } // imp1 .show(); for(frame = frames_begin; frame <= frames; frame++) { for(slice = 1; slice <= slices; slice++) { imp1.setPosition(1, slice, frame); IJ.run(imp1, "Translate...", "x=" + shift_x[frame - 1] + " y=" + shift_y[frame - 1] + " interpolation=Bicubic slice"); } } imp1.setRoi(roi_x, roi_y, roi_width, roi_height); IJ.run(imp1, "Crop", ""); // IJ.saveAs(imp1, "Tiff", folder_cell + file1 + cells_analysis_folder + "_" + IJ.pad(2 * cells_analysis_folder - 1, 2) + "_aligned.tif"); // * Préparation image dim = imp1.getDimensions(); width = dim[0]; height = dim[1]; // IJ.run("Set... ", "zoom=50 x=" + width + " y=" + height); // * Segmentation // IJ.log ("Focusing ..."); if(frames > 1) { imp1 .setSlice(KurtFocus(imp1)[0]); IJ.run (imp1, "Reduce Dimensionality...", "frames keep"); imp2 = IJ.getImage(); } else imp2 = SubstackMaker.run(imp1, String.valueOf(KurtFocus(imp1)[0])); converter = new ImageConverter(imp2); converter .convertToGray8(); imp2 .show(); imp2 .setTitle(Name + " focused"); // IJ.run ("Set... ", "zoom=50 x=" + width + " y=" + height); // IJ.log ("Segmenting ..."); IJ.run (imp1, "Z Project...", "projection=[Standard Deviation] all"); imp3 = IJ.getImage(); converter = new ImageConverter(imp3); converter .convertToGray16(); // imp3 .show(); // imp3 .setTitle("SD_Project"); // IJ.run ("Set... ", "zoom=50 x=" + width + " y=" + height); IJ.run (imp3, "Enhance Contrast", "saturated=2"); if(frames > 1) { IJ.run (imp3, "Z Project...", "projection=[Min Intensity]"); imp4 = IJ.getImage(); ic = new ImageCalculator(); imp5 = ic.run("Subtract create stack", imp3, imp4); imp4 .close(); } else imp5 = imp3.duplicate(); imp5 .show(); IJ.run (imp5, "Mean...", "radius=1 stack"); IJ.run (imp5, "Mean 3D...", "x=0 y=0 z=1"); // IJ.run ("Set... ", "zoom=50 x=" + width + " y=" + height); imp5 .setTitle("Binaries"); imp1 .close(); imp3 .close(); IJ .setTool("freehand"); Brightness (imp5, 5); if(!cells_selection) { try { IJ.saveAsTiff(imp2, folder_cell + "focused.tif"); imp2.close(); } catch (Exception e) { showDialogWithImageAndCustomOkAndNoCancel("Cells segmentation", "write.png", "Error while saving\n \n" + e.getMessage() + "\n \n" + folder_cell + "focused.tif", "The analysis is stopped at the step \"Cells segmentation\""); return; } try { IJ.saveAsTiff(imp5, folder_cell + "binaries.tif"); imp5.close(); } catch (Exception e) { imp2.close(); showDialogWithImageAndCustomOkAndNoCancel("Cells segmentation", "write.png", "Error while saving\n \n" + e.getMessage() + "\n \n" + folder_cell + "binaries.tif", "The analysis is stopped at the step \"Cells segmentation\""); return; } } // updating and saving "JEasyTFM_x_end.txt" file if(!cells_selection && (bead == 0 || bead == 2) && cells_analysis_folder == cells_analysis_ending_folder) { cells_segmentation = false; saveJob(folder + "Jobs" + File.separator + "JEasyTFM_" + job_index + "_end.txt"); } /////////////////////////////////////////////////// } // cells_segmentation if(cells_selection) { if(!cells_segmentation) { imp2 = imp5 = null; imp2 = IJ.openImage(folder_cell + "focused.tif"); if(imp2 == null) { if(!error) { error = true; showDialogWithImageAndCustomOkAndNoCancel("Cells selection", "undo.png", "The following file:\n\t\n" + folder_cell + "focused.tif\n\t\ncould not be found", "The analysis is stopped at the step \"Cells selection\""); } return; } imp5 = IJ.openImage(folder_cell + "binaries.tif"); if(imp5 == null) { if(!error) { error = true; showDialogWithImageAndCustomOkAndNoCancel("Cells selection", "undo.png", "The following file:\n\t\n" + folder_cell + "binaries.tif\n\t\ncould not be found", "The analysis is stopped at the step \"Cells selection\""); } imp2.close(); return; } imp2 .show(); imp5 .show(); } waitForUserDialog = new WaitForUserDialog("Action Required", "Select Region of interest (or nothing if there is only one cell)"); waitForUserDialog.show(); // roi = imp5.getRoi(); // if(roi != null) if(imp5.getRoi() != null) { rm = RoiManager.getInstance(); if(rm == null) rm = new RoiManager(); // rm.addRoi (roi); rm.addRoi (imp5.getRoi()); rm.select (0); IJ.run (imp5, "Make Inverse", ""); IJ.run (imp5, "Set...", "value=0 stack"); rm.runCommand (imp5, "Deselect"); IJ.run (imp5, "Select None", ""); } IJ.run("Threshold..."); IJ.setRawThreshold (imp5, 1600, 65535, null); waitForUserDialog = new WaitForUserDialog("Action Required", "Adjust Threshold"); waitForUserDialog .show(); Prefs .blackBackground = true; imp5 .hide(); IJ.run (imp5, "Make Binary", "method=Default background=Default black"); // closeWindow ("Threshold"); ThresholdAdjuster thresholdAdjuster = (ThresholdAdjuster) WindowManager.getWindow("Threshold"); thresholdAdjuster .close(); // Selection de la cellule IJ.run (imp5, "Maximum 3D...", "x=5 y=5 z=1"); IJ.run (imp5, "Fill Holes", "stack"); IJ.run (imp5, "Median..." , "radius=2 stack"); IJ.run (imp5, "Minimum...", "radius=4 stack"); // Fermeture lissage 2D // IJ.log ("Smooting 2D ..."); IJ.run (imp5, "Median..." , "radius=3 stack"); IJ.run (imp5, "Maximum...", "radius=8 stack"); IJ.run (imp5, "Fill Holes", "stack"); IJ.run (imp5, "Minimum...", "radius=10 stack"); IJ.run (imp5, "Median..." , "radius=5 stack"); imp5 .show(); for(frame = frames_begin; frame <= frames; frame++) { imp5 .setSlice(frame); biggestParticule (imp5, 200); } imp5 .hide(); // lissage temporel // IJ.log ("Smooting 3D ..."); IJ.run (imp5, "Gaussian Blur 3D..." , "x=4 y=4 z=1"); IJ.setRawThreshold (imp5, 75, 255, null); IJ.run (imp5, "Convert to Mask" , "method=Default background=Dark black"); IJ.run (imp5, "Fill Holes" , "stack"); IJ.run (imp5, "Minimum 3D..." , "x=1 y=1 z=1"); IJ.run (imp5, "Minimum..." , "radius=3 stack"); IJ.run (imp5, "Median 3D..." , "x=0 y=0 z=2"); IJ.run (imp5, "Median..." , "radius=2 stack"); IJ.run (imp5, "Make Binary" , "method=Default background=Default calculate black"); IJ.run (imp5, "Median..." , "radius=2 stack"); imp5 .show(); for(frame = frames_begin; frame <= frames; frame++) { imp5 .setSlice(frame); biggestParticule(imp5, 200); } imp5 .hide(); // Mesures IJ.run ("Set Measurements...", "area centroid shape redirect=None decimal=4"); IJ.run (imp5, "Analyze Particles...", "size=200-Infinity clear add stack"); // Fichiers de sortie rm = RoiManager.getInstance(); if(beads == 0) rm.runCommand ("Save", folder_cell + "Analysis" + File.separator + "RoiSet.zip"); else rm.runCommand ("Save", folder_cell + "Analysis_" + bead + File.separator + "RoiSet.zip"); // imp3 = FlatStack_old(imp2); // IJ.saveAs (imp3, "Tiff", folder_cell + "segmentation.tif"); FlatStack (imp2); try { IJ.saveAsTiff (imp2, folder_cell + "segmentation.tif"); } catch (Exception e) { showDialogWithImageAndCustomOkAndNoCancel("Cells segmentation", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "segmentation.tif", "The analysis is stopped at the step \"Cells segmentation\""); return; } // Show imp2 .close(); /* imp5 .setSlice(1); IJ.run ("Set... ", "zoom=50 x=" + width + " y=" + height); rm.runCommand (imp5,"Show None"); IJ.run (imp5, "Select None", ""); */ imp5 .close(); if(!force_integration) { // closeWindow ("ROI Manager"); // RoiManager rm = RoiManager.getInstance(); if(rm != null) rm.close(); } // updating and saving "JEasyTFM_x_end.txt" file if((bead == 0 || bead == 2) && cells_analysis_folder == cells_analysis_ending_folder) { if(cells_segmentation) cells_segmentation = false; cells_selection = false; saveJob(folder + "Jobs" + File.separator + "JEasyTFM_" + job_index + "_end.txt"); } /////////////////////////////////////////////////// } // cells_selection if(force_integration) { if(!cells_segmentation) { // Does the Roi file "RoiSet.zip" exist or not? if(beads == 0) file = new File(folder_cell + "Analysis" + File.separator + "RoiSet.zip"); else file = new File(folder_cell + "Analysis_" + bead + File.separator + "RoiSet.zip"); if (!file.exists()) { if(beads == 0) showDialogWithImageAndCustomOkAndNoCancel("Force integration", "undo.png", "The following file:\n\t\n" + folder_cell + "Analysis" + File.separator + "RoiSet.zip\n\t\ncould not be found", "The analysis is stopped at the step \"Force integration\""); else showDialogWithImageAndCustomOkAndNoCancel("Force integration", "undo.png", "The following file:\n\t\n" + folder_cell + "Analysis_" + bead + File.separator + "RoiSet.zip\n\t\ncould not be found", "The analysis is stopped at the step \"Force integration\""); return; } // Load the Roi file "RoiSet.zip" within the roiManager rm = RoiManager.getInstance(); if(rm == null) rm = new RoiManager(); if(beads == 0) rm.runCommand("Open", folder_cell + "Analysis" + File.separator + "RoiSet.zip"); else rm.runCommand("Open", folder_cell + "Analysis_" + bead + File.separator + "RoiSet.zip"); // reading the Transformation.txt that is already read within cells_segmentation if(beads == 0) str = IJ.openAsString(folder_cell + "Analysis" + File.separator + "Transformation.txt"); else str = IJ.openAsString(folder_cell + "Analysis_" + bead + File.separator + "Transformation.txt"); if(str.startsWith("Error")) { if(!error) { error = true; if(beads == 0) showDialogWithImageAndCustomOkAndNoCancel("Force integration", "undo.png", "The following file:\n\t\n" + folder_cell + "Analysis" + File.separator + "Transformation.txt\n\t\ncould not be opened and generated the following error message:\n \n\"" + str + "\"", "The analysis is stopped at the step \"force_integration\""); else showDialogWithImageAndCustomOkAndNoCancel("Force integration", "undo.png", "The following file:\n\t\n" + folder_cell + "Analysis_" + bead + File.separator + "Transformation.txt\n\t\ncould not be opened and generated the following error message:\n \n\"" + str + "\"", "The analysis is stopped at the step \"force_integration\""); } return; } lines = split(str, "\n"); columns = split(lines[lines.length - 1], "\t"); roi_x = Integer.parseInt(columns[0]); roi_y = Integer.parseInt(columns[1]); roi_width = Integer.parseInt(columns[2]); roi_height = Integer.parseInt(columns[3]); } color = Color.yellow; IJ .setForegroundColor(color.getRed(), color.getGreen(), color.getBlue()); rm = RoiManager.getInstance(); widthCorr = roi_width; heightCorr = roi_height; scale = new double[frames]; if(beads == 0) { checkAndCreateFolder(folder_cell + "Integration_calculation"); checkAndCreateFolder(folder_cell + "Integration_results"); } else { checkAndCreateFolder(folder_cell + "Integration_calculation_" + bead); checkAndCreateFolder(folder_cell + "Integration_results_" + bead); } // In the case the lamda values haven't been generated they can be read from the Lambda.txt file if(lambda_values == null) { if(beads == 0) lambda_values = get_lambda_values(folder_cell + "Analysis" + File.separator + "Lambda.txt"); else lambda_values = get_lambda_values(folder_cell + "Analysis_" + bead + File.separator + "Lambda.txt"); } for(frame = frames_begin; frame <= frames; frame++) { if(beads == 0) { try { copyFile(new File(folder_cell + "Analysis" + File.separator + "Stack_" + IJ.pad(frame, 2) + ".txt"), new File(folder_cell + "Integration_calculation" + File.separator + "Stack_" + IJ.pad(frame, 2) + ".txt")); } catch (Exception e) { IJ.log("File open error \n\"" + e.getMessage() + "\"\n"); } scale[frame - 1] = FTTC_main.getScaleValue(folder_cell + "Integration_calculation" + File.separator, "Stack_" + IJ.pad(frame, 2) + ".txt", length_scale, 0.5, E, lambda_values[frame - 1], unitIndex, widthCorr, heightCorr, false, false, false, false, false, false, lut); } else { try { copyFile(new File(folder_cell + "Analysis_" + bead + File.separator + "Stack_" + bead + "_" + IJ.pad(frame, 2) + ".txt"), new File(folder_cell + "Integration_calculation_" + bead + File.separator + "Stack_" + bead + "_" + IJ.pad(frame, 2) + ".txt")); } catch (Exception e) { showDialogWithImageAndCustomOkAndNoCancel("force_integration" , "write.png" , "Error while trying to copy the file\n \n" + folder_cell + "Analysis_" + bead + File.separator + "Stack_" + bead + "_" + IJ.pad(frame, 2) + ".txt\n \n onto the\n \n" + folder_cell + "Integration_calculation_" + bead + File.separator + "Stack_" + bead + "_" + IJ.pad(frame, 2) + ".txt\n \none:\n \n" + e.getMessage(), "The analysis is stopped at the step \"force_integration\""); return; } file = new File(folder_cell + "Integration_calculation_" + bead + File.separator, "Stack_" + bead + "_" + IJ.pad(frame, 2) + ".txt"); if (!file.exists()) { showDialogWithImageAndCustomOkAndNoCancel("Force integration", "undo.png", "The following file:\n\t\n" + folder_cell + "Integration_calculation_" + bead + File.separator + "Stack_" + bead + "_" + IJ.pad(frame, 2) + ".txt\n\t\ncould not be found", "The analysis is stopped at the step \"force_integration\""); return; } else { try { scale[frame - 1] = FTTC_main.getScaleValue(folder_cell + "Integration_calculation_" + bead + File.separator, "Stack_" + bead + "_" + IJ.pad(frame, 2) + ".txt", length_scale, 0.5, E, lambda_values[frame - 1], unitIndex, widthCorr, heightCorr, false, false, false, false, false, false, lut); } catch (Exception e) { showDialogWithImageAndCustomOkAndNoCancel("Force integration", "calculator.png", "Error while calculating\n \n" + e.getMessage() + "\n \n" + folder_cell + "Integration_calculation_" + bead + File.separator + "Stack_" + bead + "_" + IJ.pad(frame, 2) + ".txt" , "The analysis is stopped at the step \"force_integration\""); return; } } } // closeWindows(); } scaleMin = scaleMax = scale[0]; for(slice = 1; slice < scale.length; slice++) { if(scale[slice] > scaleMax) scaleMax = scale[slice]; else if (scale[slice] < scaleMin) scaleMin = scale[slice]; } // IJ.log("" + scaleMax + " " + niceNumber(scaleMax)); // scaleMax = 3000.0; // Measure force and area IJ.run("Set Measurements...", "area integrated redirect=None decimal=4"); for(frame = frames_begin; frame <= frames; frame++) { if(beads == 0) { file = new File(folder_cell + "Integration_calculation" + File.separator, "Traction_Stack_" + IJ.pad(frame, 2) + ".txt"); if (!file.exists()) { showDialogWithImageAndCustomOkAndNoCancel("Force integration", "undo.png", "The following file:\n\t\n" + folder_cell + "Integration_calculation" + File.separator + "Traction_Stack_" + IJ.pad(frame, 2) + ".txt\n\t\ncould not be found", "The analysis is stopped at the step \"force_integration\""); return; } else { try { if(frame == frames_begin && generate_scale) FTTC_plot.drawPlot(folder_cell + "Integration_calculation" + File.separator, "Traction_Stack_" + IJ.pad(frame, 2) + ".txt", FTTC_max_vector_length, niceNumber(scaleMax), niceNumber(scaleMax * window_area), unitIndex, widthCorr, heightCorr, true, true, true, false, false, false, lut); else FTTC_plot.drawPlot(folder_cell + "Integration_calculation" + File.separator, "Traction_Stack_" + IJ.pad(frame, 2) + ".txt", FTTC_max_vector_length, niceNumber(scaleMax), niceNumber(scaleMax * window_area), unitIndex, widthCorr, heightCorr, false, true, true, false, false, false, lut); } catch (Exception e) { showDialogWithImageAndCustomOkAndNoCancel("Force integration", "calculator.png", "Error while calculating\n \n" + e.getMessage() + "\n \n" + folder_cell + "Integration_calculation" + File.separator + "Traction_Stack_" + IJ.pad(frame, 2) + ".txt", "The analysis is stopped at the step \"force_integration\""); return; } } if(frame == frames_begin && generate_scale) { imp0 = WindowManager.getImage("Traction_Scale_Graph_in_pN_Traction_Stack_" + IJ.pad(frame, 2) + ".txt"); try { IJ.saveAsTiff(imp0, folder_cell + "Integration_calculation" + File.separator + "Traction_Vector_Scale.tif"); } catch (Exception e) { showDialogWithImageAndCustomOkAndNoCancel("Force integration", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "Integration_calculation" + File.separator + "Traction_Vector_Scale.tif", "The analysis is stopped at the step \"force_integration\""); return; } imp0.close(); } imp1 = WindowManager.getImage("Traction_Magnitude_Map_in_pN_Traction_Stack_" + IJ.pad(frame, 2) + ".txt"); try { IJ.saveAsTiff(imp1, folder_cell + "Integration_calculation" + File.separator + "Traction_Magnitude_Plot_Traction_Stack_" + IJ.pad(frame, 2) + ".tif"); } catch (Exception e) { showDialogWithImageAndCustomOkAndNoCancel("Force integration", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "Integration_calculation" + File.separator + "Traction_Magnitude_Plot_Traction_Stack_" + IJ.pad(frame, 2) + ".tif", "The analysis is stopped at the step \"force_integration\""); return; } rm.select(frame - 1); IJ.run(imp1, "Measure", ""); imp1.close(); imp2 = WindowManager.getImage("Traction_Vector_Plot_in_pN_Traction_Stack_" + IJ.pad(frame, 2) + ".txt"); try { IJ.saveAsTiff(imp2, folder_cell + "Integration_calculation" + File.separator + "Traction_Vector_Plot_Traction_Stack_" + IJ.pad(frame, 2) + ".tif"); } catch (Exception e) { showDialogWithImageAndCustomOkAndNoCancel("Force integration", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "Integration_calculation" + File.separator + "Traction_Vector_Plot_Traction_Stack_" + IJ.pad(frame, 2) + ".tif", "The analysis is stopped at the step \"force_integration\""); return; } imp2.close(); } else { file = new File(folder_cell + "Integration_calculation_" + bead + File.separator, "Traction_Stack_" + bead + "_" + IJ.pad(frame, 2) + ".txt"); if (!file.exists()) { showDialogWithImageAndCustomOkAndNoCancel("Force integration", "undo.png", "The following file:\n\t\n" + folder_cell + "Integration_calculation_" + bead + File.separator + "Traction_Stack_" + bead + "_" + IJ.pad(frame, 2) + ".txt\n\t\ncould not be found", "The analysis is stopped at the step \"force_integration\""); return; } else { try { if(frame == frames_begin && generate_scale) FTTC_plot.drawPlot(folder_cell + "Integration_calculation_" + bead + File.separator, "Traction_Stack_" + bead + "_" + IJ.pad(frame, 2) + ".txt", FTTC_max_vector_length, niceNumber(scaleMax), niceNumber(scaleMax * window_area), unitIndex, widthCorr, heightCorr, true, true, true, false, false, false, lut); else FTTC_plot.drawPlot(folder_cell + "Integration_calculation_" + bead + File.separator, "Traction_Stack_" + bead + "_" + IJ.pad(frame, 2) + ".txt", FTTC_max_vector_length, niceNumber(scaleMax), niceNumber(scaleMax * window_area), unitIndex, widthCorr, heightCorr, false, true, true, false, false, false, lut); } catch (Exception e) { showDialogWithImageAndCustomOkAndNoCancel("Force integration", "calculator.png", "Error while calculating\n \n" + e.getMessage() + "\n \n" + folder_cell + "Integration_calculation_" + bead + File.separator + "Traction_Stack_" + bead + "_" + IJ.pad(frame, 2) + ".txt", "The analysis is stopped at the step \"force_integration\""); return; } } if(frame == frames_begin && generate_scale) { imp0 = WindowManager.getImage("Traction_Scale_Graph_in_pN_Traction_Stack_" + bead + "_" + IJ.pad(frame, 2) + ".txt"); try { IJ.saveAsTiff(imp0, folder_cell + "Integration_calculation_" + bead + File.separator + "Traction_Vector_Scale.tif"); } catch (Exception e) { showDialogWithImageAndCustomOkAndNoCancel("Force integration", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "Integration_calculation_" + bead + File.separator + "Traction_Vector_Scale.tif" , "The analysis is stopped at the step \"force_integration\""); return; } imp0.close(); } imp1 = WindowManager.getImage("Traction_Magnitude_Map_in_pN_Traction_Stack_" + bead + "_" + IJ.pad(frame, 2) + ".txt"); try { IJ.saveAsTiff(imp1, folder_cell + "Integration_calculation_" + bead + File.separator + "Traction_Magnitude_Plot_Traction_Stack_" + bead + "_" + IJ.pad(frame, 2) + ".tif"); } catch (Exception e) { showDialogWithImageAndCustomOkAndNoCancel("Force integration", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "Integration_calculation_" + bead + File.separator + "Traction_Magnitude_Plot_Traction_Stack_" + bead + "_" + IJ.pad(frame, 2) + ".tif", "The analysis is stopped at the step \"force_integration\""); return; } rm.select(frame - 1); IJ.run(imp1, "Measure", ""); imp1.close(); imp2 = WindowManager.getImage("Traction_Vector_Plot_in_pN_Traction_Stack_" + bead + "_" + IJ.pad(frame, 2) + ".txt"); try { IJ.saveAsTiff(imp2, folder_cell + "Integration_calculation_" + bead + File.separator + "Traction_Vector_Plot_Traction_Stack_" + bead + "_" + IJ.pad(frame, 2) + ".tif"); } catch (Exception e) { showDialogWithImageAndCustomOkAndNoCancel("Force integration", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "Integration_calculation_" + bead + File.separator + "Traction_Vector_Plot_Traction_Stack_" + bead + "_" + IJ.pad(frame, 2) + ".tif", "The analysis is stopped at the step \"force_integration\""); return; } imp2.close(); } } // Write measurements on the image for(channel = 1; channel <= numberCh && channel != 0; channel++) { if((ch & 0x1) == 0 && (ch & 0x2) == 0 && (ch & 0x4) == 0) channel = 0; else if((ch & format[channel - 1]) == 0) continue; for(frame = frames_begin; frame <= frames; frame++) { // cellsAndForceImagesSuperposition(int light = channel, int cell = cells_analysis_folder, int bead = bead, int frame = frame, String folder = folder_cell, String folderIn, String folderOut, int pasteMode, boolean text, double scaleMax) cellsAndForceImagesSuperposition(channel, cells_analysis_folder, bead, frame, folder_cell, "Integration_calculation", "Integration_results", "Integration", "Vector" , Blitter.COPY_ZERO_TRANSPARENT, true, scaleMax); cellsAndForceImagesSuperposition(channel, cells_analysis_folder, bead, frame, folder_cell, "Integration_calculation", "Integration_results", "Integration", "Magnitude", Blitter.ADD , true, scaleMax); } if((ch & 0x1) == 0 && (ch & 0x2) == 0 && (ch & 0x4) == 0) channel--; } // closeWindow("Results"); TextWindow resultsWindow = (TextWindow) WindowManager.getWindow("Results"); // if (ResultsWindow != null) // { IJ.run("Clear Results"); resultsWindow.close(); // } // closeWindow("ROI Manager"); // RoiManager rm = RoiManager.getInstance(); if(rm != null) rm.close(); // updating and saving "JEasyTFM_x_end.txt" file if((bead == 0 || bead == 2) && cells_analysis_folder == cells_analysis_ending_folder) { force_integration = false; saveJob(folder + "Jobs" + File.separator + "JEasyTFM_" + job_index + "_end.txt"); } /////////////////////////////////////////////////// } // force_integration // updating and saving "JEasyTFM_x_end.txt" file if(bead == 0 || bead == 2) { if(cells_analysis_starting_folder < cells_analysis_ending_folder) cells_analysis_starting_folder++; else { cells_analysis = false; cells_analysis_starting_folder = 1; } saveJob(folder + "Jobs" + File.separator + "JEasyTFM_" + job_index + "_end.txt"); } /////////////////////////////////////////////////// } if(beads == 0) bead--; } } // cells_analysis private void traction_high_force() { ImagePlus imp1, imp2, stackImp, impProj, prosImp; ImageProcessor ip1 , ip2 , stackIp, stackIp2; ImageStack is; ImageConverter converter; Roi roi; String folder_cell; int traction_high_folder, bead, frame; int widthCorr = 0; int heightCorr = 0; double scaleMin; double scaleMax; double dx, dy, dx2, dy2; double x, y, width, height; int [] delta, dim; double [] scale; FileOutputStream fos; BufferedOutputStream bos; PrintWriter writer; double startTime; double stopTime; double elapsedTime; double neededTime; DecimalFormat decimalFormat = new DecimalFormat("#0.00"); /* // Particle Tracking using the 1.5. version of the Particle_Tracker code released September 2006 int radius = 5; int cutoff = 3; // int percentile = 10; int percentile = 7; int displacement = 5; */ // Particle Tracking using the 1.0.25 version of the MosaicSuite code released on 20 September 2022 int radius = 3; double cutoff = 0.0001; int percentile = 3; int displacement = 5; // for(bead = 1; bead <= format.length && bead != 0; bead++) for(bead = 1; bead <= 2 && bead != 0; bead++) { if(beads == 0) bead = 0; else if((beads & format[bead - 1]) == 0) continue; for(traction_high_folder = traction_high_starting_folder; traction_high_folder <= traction_high_ending_folder; traction_high_folder++) { folder_cell = folder + "Cell " + traction_high_folder + File.separator; if(high_piv_calculation) { for(frame = frames_begin; frame <= frames; frame++) { startTime = System.currentTimeMillis(); imp1 = imp2 = null; if(beads == 0) { imp1 = IJ.openImage(folder_cell + "Analysis" + File.separator + "CorrBeadsReference.tif"); if(imp1 == null) { if(!error) { error = true; showDialogWithImageAndCustomOkAndNoCancel("high PIV calculation", "undo.png", "The following file:\n\t\n" + folder_cell + "Analysis" + File.separator + "CorrBeadsReference.tif\n\t\ncould not be found", "The analysis is stopped at the step \"high PIV calculation\""); } return; } if(traction_high_enhance_constrast) { IJ.run (imp1, "Subtract Background...", "rolling=10 sliding"); IJ.run (imp1, "Enhance Contrast..." , "saturated=0.4 normalize"); } is = imp1.getStack(); imp2 = IJ.openImage(folder_cell + "CorrBeadsAfter" + File.separator + "CorrBeadsAfter_" + IJ.pad(frame, 2) + ".tif"); if(imp2 == null) { if(!error) { error = true; showDialogWithImageAndCustomOkAndNoCancel("high PIV calculation", "undo.png", "The following file:\n\t\n" + folder_cell + "CorrBeadsAfter" + File.separator + "CorrBeadsAfter_" + IJ.pad(frame, 2) + ".tif\n\t\ncould not be found", "The analysis is stopped at the step \"high PIV calculation\""); } imp1.close(); return; } if(traction_high_enhance_constrast) { IJ.run (imp2, "Subtract Background...", "rolling=10 sliding"); IJ.run (imp2, "Enhance Contrast..." , "saturated=0.4 normalize"); } ip2 = imp2.getProcessor(); is .addSlice(ip2); stackImp= new ImagePlus("Stack_" + IJ.pad(frame, 2) + ".tif", is); } else { imp1 = IJ.openImage(folder_cell + "Analysis_" + bead + File.separator + "CorrBeadsReference_" + bead + ".tif"); if(imp1 == null) { if(!error) { error = true; showDialogWithImageAndCustomOkAndNoCancel("high PIV calculation", "undo.png", "The following file:\n\t\n" + folder_cell + "Analysis_" + bead + File.separator + "CorrBeadsReference_" + bead + ".tif\n\t\ncould not be found", "The analysis is stopped at the step \"high PIV calculation\""); } return; } if(traction_high_enhance_constrast) { IJ.run (imp1, "Subtract Background...", "rolling=10 sliding"); IJ.run (imp1, "Enhance Contrast..." , "saturated=0.4 normalize"); } is = imp1.getStack(); imp2 = IJ.openImage(folder_cell + "CorrBeadsAfter_" + bead + File.separator + "CorrBeadsAfter_" + bead + "_" + IJ.pad(frame, 2) + ".tif"); if(imp2 == null) { if(!error) { error = true; showDialogWithImageAndCustomOkAndNoCancel("high PIV calculation", "undo.png", "The following file:\n\t\n" + folder_cell + "CorrBeadsAfter_" + bead + File.separator + "CorrBeadsAfter_" + bead + "_" + IJ.pad(frame, 2) + ".tif\n\t\ncould not be found", "The analysis is stopped at the step \"high PIV calculation\""); } imp1.close(); return; } if(traction_high_enhance_constrast) { IJ.run (imp2, "Subtract Background...", "rolling=10 sliding"); IJ.run (imp2, "Enhance Contrast..." , "saturated=0.4 normalize"); } ip2 = imp2.getProcessor(); is .addSlice(ip2); stackImp= new ImagePlus("Stack_" + bead + "_" + IJ.pad(frame, 2) + ".tif", is); } // IJ.run("Images to Stack", "name=Stack title=[] use"); // IJ.run("Translation Alignment"); // IJ.saveAs("Tiff", folder_cell + "Stack" + IJ.pad(frame, 2) + ".tif"); // IJ.selectWindow("Stack" + IJ.pad(frame, 2) + ".tif"); converter = new ImageConverter(stackImp); converter .convertToGray16(); if(debug) { stackImp .show(); // IJ.run("Reverse"); file = new File(folder_cell + "Analysis" + File.separator + "Stack_" + IJ.pad(frame, 2) + ".txt"); if(beads == 0) { if (!file.exists()) { showDialogWithImageAndCustomOkAndNoCancel("high PIV calculation", "undo.png", "The following file:\n\t\n" + folder_cell + "Analysis" + File.separator + "Stack_" + IJ.pad(frame, 2) + ".txt\n\t\ncould not be found", "The analysis is stopped at the step \"high PIV calculation\""); return; } else { try { IJ.run(stackImp, "PIV Advanced", "load piv1=48 sw1=128 vs1=16 piv2=36 sw2=64 vs2=16 piv3=24 sw3=32 vs3=" + vs3 / 2 + " correlation=2 debug_x=-1 debug_y=-1 path=/ select=[" + folder_cell + "Analysis" + File.separator + "Stack_" + IJ.pad(frame, 2) + ".txt] what=[Normalized median test and replace invalid by median then Accept this PIV and output] noise=0.20 threshold=5 c1=3 c2=1 save=[" + folder_cell + "Analysis" + File.separator + "Stack_" + IJ.pad(frame, 2) + "_2.txt]"); } catch (Exception e) { showDialogWithImageAndCustomOkAndNoCancel("high PIV calculation", "calculator.png", "Error while calculating\n \n" + e.getMessage() + "\n \n" + folder_cell + "Analysis" + File.separator + "Stack_" + IJ.pad(frame, 2) + ".txt", "The analysis is stopped at the step \"high PIV calculation\""); return; } } } else { if (!file.exists()) { showDialogWithImageAndCustomOkAndNoCancel("high PIV calculation", "undo.png", "The following file:\n\t\n" + folder_cell + "Analysis_" + bead + File.separator + "Stack_" + bead + "_" + IJ.pad(frame, 2) + ".txt\n\t\ncould not be found", "The analysis is stopped at the step \"high PIV calculation\""); return; } else { try { IJ.run(stackImp, "PIV Advanced", "load piv1=48 sw1=128 vs1=16 piv2=36 sw2=64 vs2=16 piv3=24 sw3=32 vs3=" + vs3 / 2 + " correlation=2 debug_x=-1 debug_y=-1 path=/ select=[" + folder_cell + "Analysis_" + bead + File.separator + "Stack_" + bead + "_" + IJ.pad(frame, 2) + ".txt] what=[Normalized median test and replace invalid by median then Accept this PIV and output] noise=0.20 threshold=5 c1=3 c2=1 save=[" + folder_cell + "Analysis_" + bead + File.separator + "Stack_" + bead + "_" + IJ.pad(frame, 2) + "_2.txt]"); } catch (Exception e) { showDialogWithImageAndCustomOkAndNoCancel("high PIV calculation", "calculator.png", "Error while calculating\n \n" + e.getMessage() + "\n \n" + folder_cell + "Analysis_" + bead + File.separator + "Stack_" + bead + "_" + IJ.pad(frame, 2) + ".txt", "The analysis is stopped at the step \"high PIV calculation\""); return; } } } IJ.run("Close"); if(beads == 0) { // IJ.selectWindow( "PIV3_" + "Stack_" + IJ.pad(frame, 2) + ".tif"); // IJ.saveAs("Tiff", folder_cell + "PIV3_" + "Stack_" + IJ.pad(frame, 2) + ".tif"); // IJ.run("Close"); closeWindow("PIV3_" + "Stack_" + IJ.pad(frame, 2) + ".tif"); closeWindow("PIV2_" + "Stack_" + IJ.pad(frame, 2) + ".tif"); closeWindow("PIV1_" + "Stack_" + IJ.pad(frame, 2) + ".tif"); closeWindow( "Stack_" + IJ.pad(frame, 2) + ".tif"); closeWindow( "Stack_" + IJ.pad(frame, 2) + ".tif_PIV0"); } else { // IJ.selectWindow("PIV3_" + "Stack_" + bead + "_" + IJ.pad(frame, 2) + ".tif"); // IJ.saveAs("Tiff", folder_cell + "PIV3_" + "Stack_" + bead + "_" + IJ.pad(frame, 2) + ".tif"); // IJ.run("Close"); closeWindow("PIV3_" + "Stack_" + bead + "_" + IJ.pad(frame, 2) + ".tif"); closeWindow("PIV2_" + "Stack_" + bead + "_" + IJ.pad(frame, 2) + ".tif"); closeWindow("PIV1_" + "Stack_" + bead + "_" + IJ.pad(frame, 2) + ".tif"); closeWindow( "Stack_" + bead + "_" + IJ.pad(frame, 2) + ".tif"); closeWindow( "Stack_" + bead + "_" + IJ.pad(frame, 2) + ".tif_PIV0"); } } else { if(beads == 0) { if (!file.exists()) { showDialogWithImageAndCustomOkAndNoCancel("high PIV calculation", "undo.png", "The following file:\n\t\n" + folder_cell + "Analysis" + File.separator + "Stack_" + IJ.pad(frame, 2) + "_2.txt\n\t\ncould not be found", "The analysis is stopped at the step \"high PIV calculation\""); return; } else { try { // PIV_iterative.generateAdvancedIterativePIV(stackImp, true, 64, 256, 32, 48, 128, 16, 24, 128, 8, 0.60, false, false, false, false, folder_cell + "Analysis" + File.separator + "Stack_" + IJ.pad(frame, 2) + ".txt", "Normalized median test and replace invalid by median then Accept this PIV and output", 0.20, 5, 3, 1, folder_cell + "Analysis" + File.separator + "Stack_" + IJ.pad(frame, 2) + "_2.txt"); PIV_iterative.generateAdvancedIterativePIV(stackImp, true, 48, 128, 16, 36, 64, 16, 24, 32, 8, 2, false, false, false, false, folder_cell + "Analysis" + File.separator + "Stack_" + IJ.pad(frame, 2) + ".txt", "Normalized median test and replace invalid by median then Accept this PIV and output" , 0.20, 5, 3, 1, folder_cell + "Analysis" + File.separator + "Stack_" + IJ.pad(frame, 2) + "_2.txt"); } catch (Exception e) { showDialogWithImageAndCustomOkAndNoCancel("high PIV calculation", "calculator.png", "Error while calculating\n \n" + e.getMessage() + "\n \n" + folder_cell + "Analysis" + File.separator + "Stack_" + IJ.pad(frame, 2) + "_2.txt", "The analysis is stopped at the step \"high PIV calculation\""); } } } else { if (!file.exists()) { showDialogWithImageAndCustomOkAndNoCancel("high PIV calculation", "undo.png", "The following file:\n\t\n" + folder_cell + "Analysis_" + bead + File.separator + "Stack_" + bead + "_" + IJ.pad(frame, 2) + ".txt\n\t\ncould not be found", "The analysis is stopped at the step \"high PIV calculation\""); return; } else { try { // PIV_iterative.generateAdvancedIterativePIV(stackImp, true, 64, 256, 32, 48, 128, 16, 24, 128, 8, 0.60, false, false, false, false, folder_cell + "Analysis_" + bead + File.separator + "Stack_" + bead + "_" + IJ.pad(frame, 2) + ".txt", "Normalized median test and replace invalid by median then Accept this PIV and output", 0.20, 5, 3, 1, folder_cell + "Analysis_" + bead + File.separator + "Stack_" + bead + "_" + IJ.pad(frame, 2) + "_2.txt"); PIV_iterative.generateAdvancedIterativePIV(stackImp, true, 48, 128, 16, 36, 64, 16, 24, 32, 8, 2, false, false, false, false, folder_cell + "Analysis_" + bead + File.separator + "Stack_" + bead + "_" + IJ.pad(frame, 2) + ".txt", "Normalized median test and replace invalid by median then Accept this PIV and output" , 0.20, 5, 3, 1, folder_cell + "Analysis_" + bead + File.separator + "Stack_" + bead + "_" + IJ.pad(frame, 2) + "_2.txt"); } catch (Exception e) { showDialogWithImageAndCustomOkAndNoCancel("high PIV calculation", "calculator.png", "Error while calculating\n \n" + e.getMessage() + "\n \n" + folder_cell + "Analysis_" + bead + File.separator + "Stack_" + bead + "_" + IJ.pad(frame, 2) + ".txt", "The analysis is stopped at the step \"high PIV calculation\""); return; } } } stackImp.close(); } imp1 .close(); imp2 .close(); // stackImp.close(); closeWindows(); stopTime = System.currentTimeMillis(); elapsedTime = stopTime - startTime; neededTime = (frames - frame) * elapsedTime / 60000; IJ.log("Performed calculation within the folder " + folder_cell + " on the image " + String.valueOf(frame)); IJ.log("Time needed for the calculation of the last frame: " + String.valueOf(decimalFormat.format(elapsedTime / 60000)) + " min"); IJ.log("Frames still needed to be calculated to terminate the next iterration: " + String.valueOf(frames - frame) ); if(neededTime / 60 > 1) { if(neededTime % 60 == 0) IJ.log("Linearly extrapolated time still needed to terminate the next iterration: " + String.valueOf((int) (neededTime / 60)) + " hours"); else IJ.log("Linearly extrapolated time still needed to terminate the next iterration: " + String.valueOf((int) (neededTime / 60)) + " hours and " + String.valueOf((int) (neededTime % 60)) + " min"); } else IJ.log("Linearly extrapolated time still needed to terminate the next iterration: " + String.valueOf(decimalFormat.format(neededTime)) + " min"); } // updating and saving "JEasyTFM_x_end.txt" file if((bead == 0 || bead == 2) && traction_high_folder == traction_high_ending_folder) { high_piv_calculation = false; saveJob(folder + "Jobs" + File.separator + "JEasyTFM_" + job_index + "_end.txt"); } /////////////////////////////////////////////////// } // high_piv_calculation if(particle_tracker) { for(frame = frames_begin; frame <= frames; frame++) { startTime = System.currentTimeMillis(); imp1 = imp2 = null; if(beads == 0) { imp1 = IJ.openImage(folder_cell + "Analysis" + File.separator + "CorrBeadsReference.tif"); if(imp1 == null) { if(!error) { error = true; showDialogWithImageAndCustomOkAndNoCancel("Particle tracker", "undo.png", "The following file:\n\t\n" + folder_cell + "Analysis" + File.separator + "CorrBeadsReference.tif\n\t\ncould not be found", "The analysis is stopped at the step \"Particle tracker\""); } return; } if(traction_high_enhance_constrast) { IJ.run (imp1, "Subtract Background...", "rolling=10 sliding"); IJ.run (imp1, "Enhance Contrast..." , "saturated=0.4 normalize"); } is = imp1.getStack(); imp2 = IJ.openImage(folder_cell + "CorrBeadsAfter" + File.separator + "CorrBeadsAfter_" + IJ.pad(frame, 2) + ".tif"); if(imp2 == null) { if(!error) { error = true; showDialogWithImageAndCustomOkAndNoCancel("Particle tracker", "undo.png", "The following file:\n\t\n" + folder_cell + "CorrBeadsAfter" + File.separator + "CorrBeadsAfter_" + IJ.pad(frame, 2) + ".tif\n\t\ncould not be found", "The analysis is stopped at the step \"Particle tracker\""); } imp1.close(); return; } if(traction_high_enhance_constrast) { IJ.run (imp2, "Subtract Background...", "rolling=10 sliding"); IJ.run (imp2, "Enhance Contrast..." , "saturated=0.4 normalize"); } ip2 = imp2.getProcessor(); is .addSlice(ip2); stackImp = new ImagePlus("Stack_" + IJ.pad(frame, 2) + ".tif", is); } else { imp1 = IJ.openImage(folder_cell + "Analysis_" + bead + File.separator + "CorrBeadsReference_" + bead + ".tif"); if(imp1 == null) { if(!error) { error = true; showDialogWithImageAndCustomOkAndNoCancel("Particle tracker", "undo.png", "The following file:\n\t\n" + folder_cell + "Analysis_" + bead + File.separator + "CorrBeadsReference_" + bead + ".tif\n\t\ncould not be found", "The analysis is stopped at the step \"Particle tracker\""); } return; } if(traction_high_enhance_constrast) { IJ.run (imp1, "Subtract Background...", "rolling=10 sliding"); IJ.run (imp1, "Enhance Contrast..." , "saturated=0.4 normalize"); } is = imp1.getStack(); imp2 = IJ.openImage(folder_cell + "CorrBeadsAfter_" + bead + File.separator + "CorrBeadsAfter_" + bead + "_" + IJ.pad(frame, 2) + ".tif"); if(imp2 == null) { if(!error) { error = true; showDialogWithImageAndCustomOkAndNoCancel("Particle tracker", "undo.png", "The following file:\n\t\n" + folder_cell + "CorrBeadsAfter_" + bead + File.separator + "CorrBeadsAfter_" + bead + "_" + IJ.pad(frame, 2) + ".tif\n\t\ncould not be found", "The analysis is stopped at the step \"Particle tracker\""); } imp1.close(); return; } if(traction_high_enhance_constrast) { IJ.run (imp2, "Subtract Background...", "rolling=10 sliding"); IJ.run (imp2, "Enhance Contrast..." , "saturated=0.4 normalize"); } ip2 = imp2.getProcessor(); is .addSlice(ip2); stackImp = new ImagePlus("Stack_" + bead + "_" + IJ.pad(frame, 2) + ".tif", is); } // IJ.run("Images to Stack", "name=Stack title=[] use"); // IJ.run("Translation Alignment"); // IJ.saveAs("Tiff", folder_cell + "Stack" + IJ.pad(frame, 2) + ".tif"); // IJ.selectWindow("Stack" + IJ.pad(frame, 2) + ".tif"); converter = new ImageConverter(stackImp); converter .convertToGray8(); IJ.run(stackImp, "Enhance Contrast", "saturated=0.35"); if(debug) { stackImp .show(); if(beads == 0) { /* // Particle Tracking using the 1.5. version of the Particle_Tracker code released September 2006 IJ.run ( stackImp, "Particle Tracker PIV and Trajectories Inputs ", "radius=" + radius + " cutoff=" + cutoff + " percentile=" + percentile + " link=1 displacement=" + displacement + " use_piv_file piv_file=[" + folder_cell + "Analysis" + File.separator + "Stack_" + IJ.pad(frame, 2) + "_2.txt]" ); */ // Particle Tracking using the 1.0.25 version of the MosaicSuite code released on 20 September 2022 prosImp = mosaic.plugins.ParticleTracker3DModular_.trackParticlePIVInputs ( stackImp, // ImagePlus _iInputImage, "multi", // String _trajectoryColor, radius, // int _radius, cutoff, // double _cutoff, percentile, // float _percentile, false, // boolean _absolute, false, // boolean _useClij, false, // boolean _force, // _force = false & _straight_line = false => Brownian false, // boolean _straight_line, // _force = false & _straight_line = true => Straight lines true, // boolean _drawing_trajectory, // _force = true & _straight_line = false => Constant velocity true, // boolean _drawing_particle, 1, // int _iLinkRange, displacement, // double _displacement, true, // boolean _usePivFile, folder_cell + "Analysis" + File.separator + "Stack_" + IJ.pad(frame, 2) + "_2.txt", // String _filePivDirectoryAndName folder_cell + "Analysis" + File.separator, // String _outputDirectory, "Stack_" + IJ.pad(frame, 2) + "_2_Trajectories.txt" // String _outputName ); closeWindow("Stack_" + IJ.pad(frame, 2) + ".tif"); } else { /* // Particle Tracking using the 1.5. version of the Particle_Tracker code released September 2006 IJ.run ( stackImp, "Particle Tracker PIV and Trajectories Inputs ", "radius=" + radius + " cutoff=" + cutoff + " percentile=" + percentile + " link=1 displacement=" + displacement + " use_piv_file piv_file=[" + folder_cell + "Analysis_" + bead + File.separator + "Stack_" + bead + "_" + IJ.pad(frame, 2) + "_2.txt]" ); */ // Particle Tracking using the 1.0.25 version of the MosaicSuite code released on 20 September 2022 prosImp = mosaic.plugins.ParticleTracker3DModular_.trackParticlePIVInputs ( stackImp, // ImagePlus _iInputImage, "multi", // String _trajectoryColor, radius, // int _radius, cutoff, // double _cutoff, percentile, // float _percentile, false, // boolean _absolute, false, // boolean _useClij, false, // boolean _force, // _force = false & _straight_line = false => Brownian false, // boolean _straight_line, // _force = false & _straight_line = true => Straight lines true, // boolean _drawing_trajectory, // _force = true & _straight_line = false => Constant velocity true, // boolean _drawing_particle, 1, // int _iLinkRange, displacement, // double _displacement, true, // boolean _usePivFile, folder_cell + "Analysis_" + bead + File.separator + "Stack_" + bead + "_" + IJ.pad(frame, 2) + "_2.txt", // String _filePivDirectoryAndName folder_cell + "Analysis_" + bead + File.separator, // String _outputDirectory, "Stack_" + bead + "_" + IJ.pad(frame, 2) + "_2_Trajectories.txt" // String _outputName ); closeWindow("Stack_" + bead + "_" + IJ.pad(frame, 2) + ".tif"); } if(beads == 0) { if(frame == 1) checkAndCreateFolder(folder_cell + "Trajectories"); try { IJ.saveAsTiff(prosImp, folder_cell + "Trajectories" + File.separator + "Stack_" + IJ.pad(frame, 2) + "_Trajectories.tif"); } catch (Exception e) { showDialogWithImageAndCustomOkAndNoCancel("Particle tracker", "write.png", "Error while saving\n \n" + e.getMessage() + "\n \n" + folder_cell + "Trajectories" + File.separator + "Stack_" + IJ.pad(frame, 2) + "_Trajectories.tif", "The analysis is stopped at the step \"Particle tracker\""); return; } } else { if(frame == 1) checkAndCreateFolder(folder_cell + "Trajectories_" + bead); try { IJ.saveAsTiff(prosImp, folder_cell + "Trajectories_" + bead + File.separator + "Stack_" + bead + "_" + IJ.pad(frame, 2) + "_Trajectories.tif"); } catch (Exception e) { showDialogWithImageAndCustomOkAndNoCancel("Particle tracker", "write.png", "Error while saving\n \n" + e.getMessage() + "\n \n" + folder_cell + "Trajectories_" + bead + File.separator + "Stack_" + bead + "_" + IJ.pad(frame, 2) + "_Trajectories.tif", "The analysis is stopped at the step \"Particle tracker\""); return; } } prosImp .close(); } else { if(beads == 0) /* // Particle Tracking using the 1.5. version of the Particle_Tracker code released September 2006 prosImp = Particle_Tracker_PIV_and_Trajectories_Inputs.trackParticlePIVInputs ( stackImp, false, radius, cutoff, percentile, 1, displacement, true, folder_cell + "Analysis" + File.separator + "Stack_" + IJ.pad(frame, 2) + "_2.txt" ); */ // Particle Tracking using the 1.0.25 version of the MosaicSuite code released on 20 September 2022 prosImp = mosaic.plugins.ParticleTracker3DModular_.trackParticlePIVInputs ( stackImp, // ImagePlus _iInputImage, "multi", // String _trajectoryColor, radius, // int _radius, cutoff, // double _cutoff, percentile, // float _percentile, false, // boolean _absolute, false, // boolean _useClij, false, // boolean _force, // _force = false & _straight_line = false => Brownian false, // boolean _straight_line, // _force = false & _straight_line = true => Straight lines true, // boolean _drawing_trajectory, // _force = true & _straight_line = false => Constant velocity true, // boolean _drawing_particle, 1, // int _iLinkRange, displacement, // double _displacement, true, // boolean _usePivFile, folder_cell + "Analysis" + File.separator + "Stack_" + IJ.pad(frame, 2) + "_2.txt", // String _filePivDirectoryAndName folder_cell + "Analysis" + File.separator, // String _outputDirectory, "Stack_" + IJ.pad(frame, 2) + "_2_Trajectories.txt" // String _outputName ); else /* // Particle Tracking using the 1.5. version of the Particle_Tracker code released September 2006 prosImp = Particle_Tracker_PIV_and_Trajectories_Inputs.trackParticlePIVInputs ( stackImp, false, radius, cutoff, percentile, 1, displacement, true, folder_cell + "Analysis_" + bead + File.separator + "Stack_" + bead + "_" + IJ.pad(frame, 2) + "_2.txt" ); */ // Particle Tracking using the 1.0.25 version of the MosaicSuite code released on 20 September 2022 prosImp = mosaic.plugins.ParticleTracker3DModular_.trackParticlePIVInputs ( stackImp, // ImagePlus _iInputImage, "multi", // String _trajectoryColor, radius, // int _radius, cutoff, // double _cutoff, percentile, // float _percentile, false, // boolean _absolute, false, // boolean _useClij, false, // boolean _force, // _force = false & _straight_line = false => Brownian false, // boolean _straight_line, // _force = false & _straight_line = true => Straight lines true, // boolean _drawing_trajectory, // _force = true & _straight_line = false => Constant velocity true, // boolean _drawing_particle, 1, // int _iLinkRange, displacement, // double _displacement, true, // boolean _usePivFile, folder_cell + "Analysis_" + bead + File.separator + "Stack_" + bead + "_" + IJ.pad(frame, 2) + "_2.txt", // String _filePivDirectoryAndName folder_cell + "Analysis_" + bead + File.separator, // String _outputDirectory, "Stack_" + bead + "_" + IJ.pad(frame, 2) + "_2_Trajectories.txt" // String _outputName ); stackImp .close(); if(beads == 0) { if(frame == 1) checkAndCreateFolder(folder_cell + "Trajectories"); try { IJ.saveAsTiff(prosImp, folder_cell + "Trajectories" + File.separator + "Stack_" + IJ.pad(frame, 2) + "_Trajectories.tif"); } catch (Exception e) { showDialogWithImageAndCustomOkAndNoCancel("Particle tracker", "write.png", "Error while saving\n \n" + e.getMessage() + "\n \n" + folder_cell + "Trajectories" + File.separator + "Stack_" + IJ.pad(frame, 2) + "_Trajectories.tif", "The analysis is stopped at the step \"Particle tracker\""); return; } } else { if(frame == 1) checkAndCreateFolder(folder_cell + "Trajectories_" + bead); try { IJ.saveAsTiff(prosImp, folder_cell + "Trajectories_" + bead + File.separator + "Stack_" + bead + "_" + IJ.pad(frame, 2) + "_Trajectories.tif"); } catch (Exception e) { showDialogWithImageAndCustomOkAndNoCancel("Particle tracker", "write.png", "Error while saving\n \n" + e.getMessage() + "\n \n" + folder_cell + "Trajectories_" + bead + File.separator + "Stack_" + bead + "_" + IJ.pad(frame, 2) + "_Trajectories.tif", "The analysis is stopped at the step \"Particle tracker\""); return; } } prosImp .close(); } // closeWindow("Log"); TextWindow logWindow = (TextWindow) WindowManager.getWindow("Log"); logWindow .close(); stopTime = System.currentTimeMillis(); elapsedTime = stopTime - startTime; neededTime = (frames - frame) * elapsedTime / 60000; IJ.log("Performed calculation within the folder " + folder_cell + " on the image " + String.valueOf(frame) ); IJ.log("Time needed for the calculation of the last frame: " + String.valueOf(decimalFormat.format(elapsedTime / 60000)) + " min"); IJ.log("Frames still needed to be calculated to terminate the next iterration: " + String.valueOf(frames - frame) ); if(neededTime / 60 > 1) { if(neededTime % 60 == 0) IJ.log("Linearly extrapolated time still needed to terminate the next iterration: " + String.valueOf((int) (neededTime / 60)) + " hours" ); else IJ.log("Linearly extrapolated time still needed to terminate the next iterration: " + String.valueOf((int) (neededTime / 60)) + " hours and " + String.valueOf((int) (neededTime % 60)) + " min"); } else IJ.log("Linearly extrapolated time still needed to terminate the next iterration: " + String.valueOf(decimalFormat.format(neededTime)) + " min"); } // updating and saving "JEasyTFM_x_end.txt" file if((bead == 0 || bead == 2) && traction_high_folder == traction_high_ending_folder) { particle_tracker = false; saveJob(folder + "Jobs" + File.separator + "JEasyTFM_" + job_index + "_end.txt"); } } // particle_tracker // updating and saving "JEasyTFM_x_end.txt" file if(bead == 0 || bead == 2) { if(traction_high_starting_folder < traction_high_ending_folder) traction_high_starting_folder++; else { traction_high_force = false; traction_high_starting_folder = 1; } saveJob(folder + "Jobs" + File.separator + "JEasyTFM_" + job_index + "_end.txt"); } } if(beads == 0) bead--; } } // traction_high_force private void FA_segmentation() { int FA_segmentation_folder, bead, frame; int roi_x, roi_y; int roi_width = 0; int roi_height = 0; int width, height; int i, j; double value; String folder_cell; String [] lines, columns; double [] shift_x, shift_y; RoiManager rm; ImagePlus imp, imp2, imp3, imp4, imp5; ZProjector zproj; ImageCalculator ic; NonBlockingGenericDialog nbgd; Prefs .blackBackground = true; for(bead = 1; bead <= 2 && bead != 0; bead++) { if(beads == 0) bead = 0; else if((beads & format[bead - 1]) == 0) continue; for(FA_segmentation_folder = FA_segmentation_starting_folder; FA_segmentation_folder <= FA_segmentation_ending_folder; FA_segmentation_folder++) { folder_cell = folder + "Cell " + FA_segmentation_folder + File.separator; checkAndCreateFolder(folder_cell + "FA_analysis"); // Reading of the data within the Transformation file if(beads == 0) str = IJ.openAsString(folder_cell + "Analysis" + File.separator + "Transformation.txt"); else str = IJ.openAsString(folder_cell + "Analysis_" + bead + File.separator + "Transformation.txt"); if(str.startsWith("Error")) { if(!error) { error = true; if(beads == 0) showDialogWithImageAndCustomOkAndNoCancel("Force integration", "undo.png", "The following file:\n\t\n" + folder_cell + "Analysis" + File.separator + "Transformation.txt\n\t\ncould not be opened and generated the following error message:\n \n\"" + str + "\"", "The analysis is stopped at the step \"force_integration\""); else showDialogWithImageAndCustomOkAndNoCancel("Force integration", "undo.png", "The following file:\n\t\n" + folder_cell + "Analysis_" + bead + File.separator + "Transformation.txt\n\t\ncould not be opened and generated the following error message:\n \n\"" + str + "\"", "The analysis is stopped at the step \"force_integration\""); } return; } lines = split(str, "\n"); if(lines.length <= 3) { showDialogWithImageAndCustomOkAndNoCancel("Cells segmentation", "calculator.png", "The format of the data imported from the following file:\n \n" + folder_cell + "Analysis" + File.separator + "Transformation.txt\n \n\nare not correct!\n \nPlease check the content of the file.", "The analysis is stopped at the step \"Cells segmentation\""); return; } shift_x = new double[lines.length - 3]; shift_y = new double[lines.length - 3]; for (int line = 1; line < lines.length - 2; line++) { columns = split(lines[line], "\t"); shift_x[line - 1] = Double.valueOf(columns[1]); shift_y[line - 1] = Double.valueOf(columns[2]); } columns = split(lines[lines.length - 1], "\t"); roi_x = Integer.parseInt(columns[0]); roi_y = Integer.parseInt(columns[1]); roi_width = Integer.parseInt(columns[2]); roi_height = Integer.parseInt(columns[3]); // Reading of the raw hyperstack imp = openStealth (folder + file1 + FA_segmentation_folder + "_" + IJ.pad((numberCh + 1) * FA_segmentation_folder - numberCh + 1, 2) + ".tif"); if(imp == null) { showDialogWithImageAndCustomOkAndNoCancel("FA_segmentation", "undo.png", "The following file:\n\t\n" + folder + file1 + FA_segmentation_folder + "_" + IJ.pad((numberCh + 1) * FA_segmentation_folder - numberCh + 1, 2) + ".tif\n\t\ncould not be found", "The analysis is stopped at the step \"FA_segmentation\""); return; } try { imp = HyperStackConverter.toHyperStack(imp, 1, slices, frames, "default", "Grayscale"); } catch (Exception e) { showDialogWithImageAndCustomOkAndNoCancel("FA_segmentation", "calculator.png", "Error while trying to transform the stack image \n" + imp.getTitle() + "\ncontaining " + imp.getStackSize() + " images into an hyperStack of\nChannels 1\nSlices " + slices + "\nFrames " + frames + "\ni.e. " + slices * frames + " images" , "The analysis is stopped at the step \"FA_segmentation\""); return; } // imp.show(); // frame = frames_begin; for(frame = frames_begin; frame <= frames; frame++) { imp2 = SubHyperstackMaker.makeSubhyperstack(imp, "1", "1-" + slices, "" + frame); // if(beads_sequence_images_find_focused_slices) // imp2 = Find_Focused_Slices.getAlignedSlices(imp2, 80, 0.00, true, true, false); // imp2 .show(); imp3 = imp2.duplicate(); // IJ .run(imp3, "Enhance Contrast", "saturated=0.35"); IJ .run(imp3, "Gaussian Blur...", "sigma=1 stack"); IJ .run(imp3, "Subtract Background...", "rolling=3 stack"); for(i = 1; i <= imp3.getNSlices(); i++) { imp3.setSlice(i); IJ .run(imp3, "Find Maxima...", "prominence=75 output=Count"); } ResultsTable rt = Analyzer.getResultsTable(); j = 0; value = rt.getValue("Count" , 0); for(i = 1; i < rt.getCounter(); i++) { if(rt.getValue("Count" , i) > value) { value = rt.getValue("Count" , i); j = i; } } /* imp2 .setSlice(j); imp2 .show(); nbgd = new NonBlockingGenericDialog ("Action Required"); nbgd .addMessage ("Please select the best focused image"); nbgd .hideCancelButton(); nbgd .setOKLabel("Continue"); nbgd .showDialog(); imp3 = new Duplicator().run(imp2, imp2.getCurrentSlice(), imp2.getCurrentSlice()); */ // imp3 = new Duplicator().run(imp2, j, j); imp3 = new Duplicator().run(imp3, j, j); imp2 .close(); // imp3 = IJ.openImage(folder_cell + "Cells_Ch1_" + IJ.pad(frame, 2) + ".tif"); // imp3 .show(); imp4 = imp3.duplicate(); IJ .run(imp4, "Mean...", "radius=20"); ic = new ImageCalculator(); imp5 = ic.run("Subtract create", imp3, imp4); imp5 .show(); IJ .run(imp5, "Translate...", "x=" + shift_x[frame - 1] + " y=" + shift_y[frame - 1] + " interpolation=Bicubic slice"); imp5 .setRoi(roi_x, roi_y, roi_width, roi_height); IJ .run(imp5, "Crop", ""); IJ .run(imp5, "Enhance Contrast", "saturated=0.35"); if(beads == 0) { try { IJ.saveAsTiff(imp5, folder_cell + "FA_Analysis" + File.separator + "CorrCells_" + IJ.pad(frame, 2) + ".tif"); } catch (Exception e) { showDialogWithImageAndCustomOkAndNoCancel("FA_segmentation", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "FA_Analysis" + File.separator + "CorrCells_" + IJ.pad(frame, 2) + ".tif", "The analysis is stopped at the step \"FA_segmentation\""); return; } } else { try { IJ.saveAsTiff(imp5, folder_cell + "FA_Analysis" + File.separator + "CorrCells_" + bead + "_" + IJ.pad(frame, 2) + ".tif"); } catch (Exception e) { showDialogWithImageAndCustomOkAndNoCancel("FA_segmentation", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "FA_Analysis" + File.separator + "CorrCells_" + bead + "_" + IJ.pad(frame, 2) + ".tif", "The analysis is stopped at the step \"FA_segmentation\""); return; } } IJ .setAutoThreshold(imp, "Li dark"); IJ .run("Threshold..."); nbgd = new NonBlockingGenericDialog ("Action Required"); nbgd .addMessage ("Please adjust the threshold settings"); nbgd .hideCancelButton(); nbgd .setOKLabel("Continue"); nbgd .showDialog(); IJ .run(imp5, "Convert to Mask", ""); IJ .selectWindow("Threshold"); IJ .run("Close"); if(beads == 0) { try { IJ.saveAsTiff(imp5, folder_cell + "FA_Analysis" + File.separator + "CorrCells_" + IJ.pad(frame, 2) + "_binary.tif"); } catch (Exception e) { showDialogWithImageAndCustomOkAndNoCancel("FA_segmentation", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "FA_Analysis" + File.separator + "CorrCells_" + IJ.pad(frame, 2) + "_binary.tif", "The analysis is stopped at the step \"FA_segmentation\""); return; } } else { try { IJ.saveAsTiff(imp5, folder_cell + "FA_Analysis" + File.separator + "CorrCells_" + bead + "_" + IJ.pad(frame, 2) + "_binary.tif"); } catch (Exception e) { showDialogWithImageAndCustomOkAndNoCancel("FA_segmentation", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "FA_Analysis" + File.separator + "CorrCells_" + bead + "_" + IJ.pad(frame, 2) + "_binary.tif", "The analysis is stopped at the step \"FA_segmentation\""); return; } } IJ .run(imp5, "Analyze Particles...", "size=10-Infinity clear add"); /* imp2 = null; if(beads == 0) imp2 = IJ.openImage(folder_cell + "FA_Analysis" + File.separator + "CorrCells_" + IJ.pad(frame, 2) + ".tif"); else imp2 = IJ.openImage(folder_cell + "FA_Analysis" + File.separator + "CorrCells_" + bead + "_" + IJ.pad(frame, 2) + ".tif"); if(imp2 == null) { if(beads == 0) showDialogWithImageAndCustomOkAndNoCancel("FA_segmentation", "undo.png", "The following file:\n\t\n" + folder_cell + "FA_Analysis" + File.separator + "CorrCells_" + IJ.pad(frame, 2) + ".tif\n\t\ncould not be found", "The analysis is stopped at the step \"FA_segmentation\""); else showDialogWithImageAndCustomOkAndNoCancel("FA_segmentation", "undo.png", "The following file:\n\t\n" + folder_cell + "FA_Analysis" + File.separator + "CorrCells_" + bead + "_" + IJ.pad(frame, 2) + ".tif\n\t\ncould not be found", "The analysis is stopped at the step \"FA_segmentation\""); return; } imp2 .show(); */ rm = RoiManager.getInstance(); if(rm == null) rm = new RoiManager (); // rm .runCommand(imp2, "Show All without labels"); rm .runCommand(imp5, "Show All without labels"); if(beads == 0) rm .runCommand("Save", folder_cell + "FA_Analysis" + File.separator + "ROI_set_" + IJ.pad(frame, 2) + ".zip"); else rm .runCommand("Save", folder_cell + "FA_Analysis" + File.separator + "ROI_set_" + bead + "_" + IJ.pad(frame, 2) + ".zip"); nbgd = new NonBlockingGenericDialog ("Action Required"); nbgd .addMessage ("Visualize your results"); nbgd .hideCancelButton(); nbgd .setOKLabel("Continue"); nbgd .showDialog(); // imp2 .close(); imp5 .close(); IJ .selectWindow("ROI Manager"); IJ .run("Close"); } // FA_segmentation() imp.close(); // updating and saving "JEasyTFM_x_end.txt" file if(bead == 0 || bead == 2) { if(FA_segmentation_starting_folder < FA_segmentation_ending_folder) FA_segmentation_starting_folder++; else { FA_segmentation = false; FA_segmentation_starting_folder = 1; } saveJob(folder + "Jobs" + File.separator + "JEasyTFM_" + job_index + "_end.txt"); } } if(beads == 0) bead--; } } // FA_segmentation private void traction_force_applied_on_FA() { ImagePlus imp, imp1, imp2, beadsPlotImp, lambdaPlotImp, forcePlotImp; Plot beadsPlot , lambdaPlot , forcePlot; RoiManager rm; Roi [] rois; final char [] charLambda = { ( char ) 955 }; final String symbolLambda = new String( charLambda ); final double conversionFactor = E * Math.pow(length_scale, 2); // force[nN] = E[kPa] * [pixel/micron]^2 boolean set_cero = true; int i, j, k; int image_width, image_height; int beads_size_initial, FA_size_initial; int traction_force_applied_on_FA_folder, bead, channel, frame; int displacement_maximum_index = 0;; int offset = 13; int DF; // Degrees of freedom int delLines = 0; int iset = 0; int delta1 = 5; int delta2 = 0; int delta3 = 1000; int lsMin = -3; // Minima of the logspace vector lambda_v int lsMax = 1; // Maxima of the logspace vector lambda_v int lsSize = 30; // Size of the logspace vector lambda_v double scale = 2.0; // scaling factore for the force plotting graph double sigma = 1.0; double rhoMin = 0.0; double rhoMax = 0.0; double lambda; double length, min_length; double displacement_maximum = 0.0; double displacement_magnitude; double rho_opt; double rho_opt_plus; double rho_opt_minus; double mag; double val1, val2; // temporary double values; // double [] sf; ArrayList focalsX = new ArrayList (); ArrayList focalsY = new ArrayList (); ArrayList beads1X = new ArrayList (); ArrayList beads1Y = new ArrayList (); ArrayList beads2X = new ArrayList (); ArrayList beads2Y = new ArrayList (); ArrayList u = new ArrayList (); ArrayList s = new ArrayList (); ArrayList FX = new ArrayList (); ArrayList FY = new ArrayList (); ArrayList lambda_v = new ArrayList (); ArrayList beta = new ArrayList (); ArrayList zeta = new ArrayList (); ArrayList eta = new ArrayList (); ArrayList rho = new ArrayList (); double [] centroids; // String folder_begin, folder_cell; String folder_cell; String [] lines, columns; // This plugin is the translation into an ImageJ plugin of the code // developped under Matlab by Ulrich Schwarz, MPI Colloids and Interfaces // http://www.thphys.uni-heidelberg.de/~biophys/index.php?lang=e&n1=research_elasticsubstrates // for the Inverse problem for elastic substrate method // that he had written May 2000, modified Feb 2003. // // INPUT: lines.dat contains displacement data in form x1 y1 x2 y2 // focals.dat contains positions of focals in form x1 y1 // OUTPUT: newlines.dat contains displacement data in form x1 y1 x2 y2 // force_(lambda value).dat contains the calculated forces in form x1 y1 for(traction_force_applied_on_FA_folder = traction_applied_on_FA_starting_folder; traction_force_applied_on_FA_folder <= traction_applied_on_FA_ending_folder; traction_force_applied_on_FA_folder++) { folder_cell = folder + "Cell " + traction_force_applied_on_FA_folder + File.separator; checkAndCreateFolder(folder_cell + "Traction_force_on_FA"); for(frame = frames_begin; frame <= frames; frame++) { // Opening of the cell image imp = null; if(beads == 0) { imp = IJ.openImage(folder_cell + "FA_Analysis" + File.separator + "CorrCells_" + IJ.pad(frame, 2) + ".tif"); if (imp == null) { if(!error) { error = true; showDialogWithImageAndCustomOkAndNoCancel("Traction force applied on FA", "undo.png", "The following file:\n\t\n" + folder_cell + "FA_Analysis" + File.separator + "CorrCells_" + IJ.pad(frame, 2) + ".tif\n\t\ncould not be found", "The analysis is stopped at the step \"Traction force applied on FA\""); } return; } } else { imp1 = imp2 = null; bead = 1; if((beads & format[bead - 1]) != 0) { imp1 = IJ.openImage(folder_cell + "FA_Analysis_" + bead + File.separator + "CorrCells_" + bead + "_" + IJ.pad(frame, 2) + ".tif"); imp1.show(); } bead = 2; if((beads & format[bead - 1]) != 0) { imp2 = IJ.openImage(folder_cell + "FA_Analysis_" + bead + File.separator + "CorrCells_" + bead + "_" + IJ.pad(frame, 2) + ".tif"); imp2.show(); } if(imp1 == null) { if(imp2 == null) { if(!error) { error = true; showDialogWithImageAndCustomOkAndNoCancel("Traction force applied on FA", "undo.png", "The following files:\n\t\n" + folder_cell + "FA_Analysis_1" + File.separator + "CorrCells_1_" + IJ.pad(frame, 2) + ".tif\n\t\nand\n\t\n" + folder_cell + "FA_Analysis_2" + File.separator + "CorrCells_2_" + IJ.pad(frame, 2) + ".tif\n\t\n could not be found", "The analysis is stopped at the step \"Traction force applied on FA\""); } return; } else { imp = imp2.duplicate(); imp2.close(); } } else { if(imp2 == null) { imp = imp1.duplicate(); imp1.close(); } else { IJ.selectWindow(imp1.getTitle()); IJ.run("Add Image...", "image=" + imp2.getTitle() + " x=0 y=0 opacity=50"); imp = imp1.duplicate(); imp1.close(); imp2.close(); } } } // imp.show(); // Reading of the beads displacements data str = null; lines = null; if(beads == 0) { str = IJ.openAsString(folder_cell + "Analysis" + File.separator + "Stack_" + IJ.pad(frame, 2) + "_2_Trajectories.txt"); if(str.startsWith("Error")) { if(!error) { error = true; showDialogWithImageAndCustomOkAndNoCancel("Traction force applied on FA", "undo.png", "The following file:\n\t\n" + folder_cell + "Analysis" + File.separator + "Stack_" + IJ.pad(frame, 2) + "_2_Trajectories.txt\n\t\ncould not be found", "The analysis is stopped at the step \"Traction force applied on FA\""); } return; } lines = str.split("\n"); lines = Arrays.copyOfRange(lines, offset, lines.length); } else { bead = 1; str = IJ.openAsString(folder_cell + "Analysis_" + bead + File.separator + "Stack_" + bead + "_" + IJ.pad(frame, 2) + "_2_Trajectories.txt"); if(str.startsWith("Error")) { // showDialogWithImageAndCustomOkAndNoCancel("Traction force applied on FA", "undo.png", "The following file:\n\t\n" + folder_cell + "Analysis_" + bead + File.separator + "Stack_" + bead + "_" + IJ.pad(frame, 2) + "_2_Trajectories.txt\n\t\ncould not be found", "The analysis is stopped at the step \"Traction force applied on FA\""); } else { lines = str.split("\n"); lines = Arrays.copyOfRange(lines, offset, lines.length); } columns = null; bead = 2; str = IJ.openAsString(folder_cell + "Analysis_" + bead + File.separator + "Stack_" + bead + "_" + IJ.pad(frame, 2) + "_2_Trajectories.txt"); if(str.startsWith("Error")) { // showDialogWithImageAndCustomOkAndNoCancel("Traction force applied on FA", "undo.png", "The following file:\n\t\n" + folder_cell + "Analysis_" + bead + File.separator + "Stack_" + bead + "_" + IJ.pad(frame, 2) + "_2_Trajectories.txt\n\t\ncould not be found", "The analysis is stopped at the step \"Traction force applied on FA\""); } else { columns = str.split("\n"); // columns is used here as temporary String[] to avoid the need to define such a new array as temporary columns = Arrays.copyOfRange(columns, offset, columns.length); } if(lines == null) { if(columns == null) { showDialogWithImageAndCustomOkAndNoCancel("Traction force applied on FA", "undo.png", "The following files:\n\t\n" + folder_cell + "Analysis_1" + File.separator + "Stack_1_" + IJ.pad(frame, 2) + "_2_Trajectories.txt\n\t\nand\n\t\n" + folder_cell + "Analysis_2" + File.separator + "Stack_2_" + IJ.pad(frame, 2) + "_2_Trajectories.txt\n\t\n could not be found", "The analysis is stopped at the step \"Traction force applied on FA\""); return; } else { lines = Arrays.copyOfRange(columns, 0, columns.length); columns = null; } } else { if(columns == null) { // nothing to do given that String[] lines is already defined as needed } else { ArrayList both = new ArrayList(Arrays.asList(lines)); both.addAll(Arrays.asList(columns)); lines = both.toArray(new String[0]); columns = null; } } } beads1X.clear(); beads2X.clear(); beads1Y.clear(); beads2Y.clear(); for(i = 0; i != lines.length; i++) { columns = split(lines[i],"\t"); beads1X .add( Double.valueOf(columns[0])); beads1Y .add(imp.getHeight() - Double.valueOf(columns[1])); beads2X .add( Double.valueOf(columns[2])); beads2Y .add(imp.getHeight() - Double.valueOf(columns[3])); } // Reading of the beads displacements data rm = RoiManager.getRoiManager(); // if(rm == null) rm = new RoiManager(); for(bead = 1; bead <= 2 && bead != 0; bead++) { if(beads == 0) bead = 0; else if((beads & format[bead - 1]) == 0) continue; if(beads == 0) { file = new File(folder_cell + "FA_Analysis" + File.separator + "ROI_set_" + IJ.pad(frame, 2) + ".zip"); if (!file.exists()) { showDialogWithImageAndCustomOkAndNoCancel("Traction force applied on FA", "undo.png", "The following file:\n\t\n" + folder_cell + "FA_Analysis" + File.separator + "ROI_set_" + IJ.pad(frame, 2) + ".zip\n\t\ncould not be found", "The analysis is stopped at the step \"Traction force applied on FA\""); return; } else if(!rm.open(folder_cell + "FA_Analysis" + File.separator + "ROI_set_" + IJ.pad(frame, 2) + ".zip")) { showDialogWithImageAndCustomOkAndNoCancel("Traction force applied on FA", "undo.png", "The following file:\n\t\n" + folder_cell + "FA_Analysis" + File.separator + "ROI_set_" + IJ.pad(frame, 2) + ".zip\n\t\ncould not be found", "The analysis is stopped at the step \"Traction force applied on FA\""); return; } } else { file = new File(folder_cell + "FA_Analysis_" + bead + File.separator + "ROI_set_" + bead + "_" + IJ.pad(frame, 2) + ".zip"); if (!file.exists()) { showDialogWithImageAndCustomOkAndNoCancel("Traction force applied on FA", "undo.png", "The following file:\n\t\n" + folder_cell + "FA_Analysis_" + bead + File.separator + "ROI_set_" + bead + "_" + IJ.pad(frame, 2) + ".zip\n\t\ncould not be found", "The analysis is stopped at the step \"Traction force applied on FA\""); return; } else if(!rm.open(folder_cell + "FA_Analysis_" + bead + File.separator + "ROI_set_" + bead + "_" + IJ.pad(frame, 2) + ".zip")) { showDialogWithImageAndCustomOkAndNoCancel("Traction force applied on FA", "undo.png", "The following file:\n\t\n" + folder_cell + "FA_Analysis_" + bead + File.separator + "ROI_set_" + bead + "_" + IJ.pad(frame, 2) + ".zip\n\t\ncould not be found", "The analysis is stopped at the step \"Traction force applied on FA\""); return; } } if(beads == 0) bead--; } rois = rm.getRoisAsArray(); rm .close(); focalsX.clear(); focalsY.clear(); for(i = 0; i != rois.length; i++) { centroids = rois[i].getContourCentroid(); focalsX .add(centroids[0]); // focalsY .add(centroids[1]); focalsY .add(imp.getHeight() - centroids[1]); } // saveFocalsData try { FileWriter fstream = new FileWriter(folder_cell + "Traction_force_on_FA" + File.separator + "FA_positions_" + IJ.pad(frame, 2) + ".txt"); BufferedWriter fileOutputStream = new BufferedWriter(fstream); for(i = 0; i < focalsX.size(); i++) fileOutputStream.write( String.valueOf(focalsX.get(i)) + "\t" + String.valueOf(focalsY.get(i)) + "\n" ); fileOutputStream.close(); } catch (Exception e) { showDialogWithImageAndCustomOkAndNoCancel("Traction force applied on FA", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "Traction_force_on_FA" + File.separator + "FA_positions_" + IJ.pad(frame, 2) + ".txt", "The analysis is stopped at the step \"Traction force applied on FA\""); } image_width = imp.getWidth(); image_height = imp.getHeight(); beads_size_initial = beads1X.size(); FA_size_initial = focalsX.size(); beadsPlot = new Plot ("Data before correction", "X Axis", "Y Axis"); beadsPlot .setLimits (0., image_width, 0., image_height); // beadsPlot .show (); Rectangle beadsPlotDrawingFrame = beadsPlot.getDrawingFrame(); Dimension beadsPlotSize = beadsPlot.getSize(); beadsPlot .setSize (beadsPlotSize.width + (image_width - beadsPlotDrawingFrame.width), beadsPlotSize.height + (image_height - beadsPlotDrawingFrame.height)); // beadsPlot .update (); beadsPlot .setColor (Color.red); beadsPlot .setLineWidth (2); beadsPlot .addPoints (focalsX, focalsY, Plot.BOX); beadsPlot .setColor (Color.blue); beadsPlot .setLineWidth (1); beadsPlot .drawVectors (beads1X, beads1Y, beads2X, beads2Y); IJ .run (imp, "Enhance Contrast", "saturated=0.35"); IJ .run (imp, "RGB Color", ""); // IJ .run (imp, "Invert", ""); beadsPlot .show (); beadsPlotImp = beadsPlot.getImagePlus(); // plotScaleBar Calibration beadsPlotCalibration = new Calibration(); beadsPlotCalibration .pixelWidth = length_scale; beadsPlotCalibration .pixelHeight = length_scale; beadsPlotCalibration .setXUnit ( "\u00B5m" ); // beadsPlotImp .setGlobalCalibration (beadsPlotCalibration); beadsPlotImp .setCalibration (beadsPlotCalibration); // IJ.run(beadsPlotImp, "Scale Bar...", "width=10 height=1 thickness=4 font=16 color=Blue background=None location=[Upper Right] bold overlay"); IJ.run(beadsPlotImp, "Scale Bar...", "width=10 height=1 thickness=4 font=16 color=Blue background=None location=[Upper Right] horizontal bold overlay"); // IJ.run(forcePlotImp, "Scale Bar...", "width=10 height=1 thickness=4 font=16 color=Blue background=None location=[Upper Right] horizontal vertical bold overlay"); beadsPlot .setFrozen (true); try { IJ .saveAsTiff (beadsPlotImp, folder_cell + "Traction_force_on_FA" + File.separator + "Beads_displacement_plot_" + IJ.pad(frame, 2) + ".tif"); } catch (Exception e) { showDialogWithImageAndCustomOkAndNoCancel("Traction force applied on FA", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "Traction_force_on_FA" + File.separator + "Beads_displacement_plot_" + IJ.pad(frame, 2) + ".tif", "The analysis is stopped at the step \"Traction force applied on FA\""); } imp .copy (); // beadsPlot .setFrozen (true); beadsPlotDrawingFrame = beadsPlot.getDrawingFrame(); beadsPlotImp .paste (beadsPlotDrawingFrame.x, beadsPlotDrawingFrame.y, "XOR"); beadsPlot .update (); try { IJ .saveAsTiff (beadsPlotImp, folder_cell + "Traction_force_on_FA" + File.separator + "Beads_displacement_plot_with_image_" + IJ.pad(frame, 2) + ".tif"); } catch (Exception e) { showDialogWithImageAndCustomOkAndNoCancel("Traction force applied on FA", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "Traction_force_on_FA" + File.separator + "Beads_displacement_plot_with_image_" + IJ.pad(frame, 2) + ".tif", "The analysis is stopped at the step \"Traction force applied on FA\""); } beadsPlotImp .close(); // imp .close(); // reformatAndSaveCorrectedData() // Set displacements to zero which are smaller than delta2 ? // This feature I used a lot in the beginning, since I figured // that small displacements only represent noise and should not be used; // now I think that there is no reason to exclude them, the // method itself is able to handle the noise problem by itself // remove all displacements which are closer to any focal than delta1 // This is important since we assume point-like forces which diverge at the origin; // it can be shown that this approximates distributed force well as long as // the displacement is evaluated at distances to the ellipse which are larger // than the ellipse itself // Remove displacements which are farer away from any focal than delta3 // This is not necessary, but reasonable, since for displacements far // way, the signal decays below the noise level displacement_maximum = getDistance(beads1X.get(0), beads2X.get(0), beads1Y.get(0), beads2Y.get(0)); for(j = 1; j < beads1X.size(); j++) { displacement_magnitude = getDistance(beads1X.get(j), beads2X.get(j), beads1Y.get(j), beads2Y.get(j)); if (displacement_magnitude > displacement_maximum) { displacement_maximum_index = j; displacement_maximum = displacement_magnitude; } min_length = getDistance(focalsX.get(0), beads1X.get(j), focalsY.get(0), beads1Y.get(j)); for(i = 1; i < focalsX.size(); i++) { length = getDistance(focalsX.get(i), beads1X.get(j), focalsY.get(i), beads1Y.get(j)); if(length < min_length) min_length = length; } if ((min_length < delta1) || (min_length > delta3)) { delLines++; beads1X.remove(j); beads1Y.remove(j); beads2X.remove(j); beads2Y.remove(j); } } iset = 0; if(set_cero) // set small displacements to cero if requested { for(i = 0; i < beads1X.size(); i++) { if(getDistance(beads1X.get(i), beads2X.get(i), beads1Y.get(i), beads2Y.get(i)) < delta2) { beads2X.set(i, beads1X.get(i)); beads2Y.set(i, beads1Y.get(i)); iset++; } } } // saveBeadsData(getfileLinesDirectory(fileLinesFullName) + File.separator + fileNewLinesName); try { FileWriter fstream = new FileWriter(folder_cell + "Traction_force_on_FA" + File.separator + "Beads_displacements_" + IJ.pad(frame, 2) + ".txt"); BufferedWriter fileOutputStream = new BufferedWriter(fstream); for(i = 0; i < beads1X.size(); i++) fileOutputStream.write( String.valueOf(beads1X.get(i)) + "\t" + String.valueOf(beads1Y.get(i)) + "\t" + String.valueOf(beads2X.get(i)) + "\t" + String.valueOf(beads2Y.get(i)) + "\n" ); fileOutputStream.close(); } catch (Exception e) { showDialogWithImageAndCustomOkAndNoCancel("Traction force applied on FA", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "Traction_force_on_FA" + File.separator + "Beads_displacements_" + IJ.pad(frame, 2) + ".txt", "The analysis is stopped at the step \"Traction force applied on FA\""); } // Implementation of the inverse.m code // standard deviation for noise in displacement // from this we can calculate an estimate for the regularization parameter lambda // displacements is stored both as one large vector u u.clear(); for(i = 0; i < 2 * beads1X.size(); i++) u.add(calcultateU(i, beads1X, beads1Y, beads2X, beads2Y)); // Number of degrees of freedom DF = 2 * ( beads1X.size() - focalsX.size() ); /* // estimate for residual norm and its confidence interval rho_opt = Math.sqrt(DF) * sigma; rho_opt_plus = (Math.sqrt(DF) + Math.pow(2 * DF, 0.25)) * sigma; rho_opt_minus = (Math.sqrt(DF) - Math.pow(2 * DF, 0.25)) * sigma; */ IJ.showStatus("Done..."); // calculateG() IJ.showStatus("Calculating G ..."); // build Greens function between the two sets of positions RealMatrix G = MatrixUtils.createRealMatrix(2 * beads1X.size(), 2 * focalsX.size()); // G = new Matrix(2 * beads1X.size(), 2 * focalsX.size()); for(i = 0; i < 2 * beads1X.size(); i++) for(j = 0; j < 2 * focalsX.size(); j++) G.setEntry(i, j, Greens(i, j, focalsX, focalsY, beads1X, beads1Y)); // G.set(i, j, Greens(i, j)); // singular value decomposition for G SingularValueDecomposition S = new SingularValueDecomposition(G); // S = G.svd(); RealMatrix U = (S.getU()).scalarMultiply (-1); double[] sf = S .getSingularValues (); RealMatrix V = (S.getV()).scalarMultiply (-1); // U = (S.getU()).times(-1); // sf = S.getSingularValues(); // V = (S.getV()).times(-1); s.clear(); for(i = 0; i < sf.length; i++) s.add( sf[i] ); // logspace generation for lambda_v lambda_v.clear(); val1 = (double) (lsMax - lsMin) / (lsSize - 1); for(i = 0; i < lsSize; i++) lambda_v.add( Math.pow(10, lsMin + (val1 * i)) ); // [F_v,rho_v,eta_v] = tikhonov(U,s,V,u,lambda_v); tikhonovVect(U, s, V, u, lambda_v, beta, zeta, eta, rho); /* // Transformation of lambda_v into Log(lambda_v) for(i = 0; i < lsSize; i++) lambda_v.set(i, Math.log( lambda_v.get(i) )); */ rhoMin = getRhoMinima(rho); rhoMax = getRhoMaxima(rho); sigma = (rhoMax + rhoMin) / (2 * Math.sqrt(DF)); // estimate for residual norm and its confidence interval rho_opt = Math.sqrt(DF) * sigma; rho_opt_plus = (Math.sqrt(DF) + Math.pow(2 * DF, 0.25)) * sigma; rho_opt_minus = (Math.sqrt(DF) - Math.pow(2 * DF, 0.25)) * sigma; lambdaPlot = new Plot ("Choice of regularization parameter", symbolLambda, "residual norm || A x - b ||_2"); lambdaPlot .setAxes (true, false, true, true, true, true, 10, 5); lambdaPlot .setXLabelFont ( new Font("Helvetica", Font.PLAIN, 18) ); lambdaPlot .setLimits (lambda_v.get( 0 ), lambda_v.get( lambda_v.size() - 1 ), Math.floor(rhoMin), Math.ceil(rhoMax)); lambdaPlot .setSize (1584, 765); lambdaPlot .setColor (Color.blue); // lambdaPlot .setLineWidth (1); lambdaPlot .addPoints (lambda_v, rho, Plot.LINE); lambdaPlot .setColor (Color.red); lambdaPlot .drawLine (lambda_v.get( 0 ), rho_opt , lambda_v.get( lambda_v.size() - 1 ), rho_opt); lambdaPlot .drawDottedLine (lambda_v.get( 0 ), rho_opt_plus , lambda_v.get( lambda_v.size() - 1 ), rho_opt_plus, 2); lambdaPlot .drawDottedLine (lambda_v.get( 0 ), rho_opt_minus, lambda_v.get( lambda_v.size() - 1 ), rho_opt_minus, 2); lambdaPlot .show (); lambdaPlotImp = lambdaPlot.getImagePlus(); try { IJ .saveAsTiff (lambdaPlotImp, folder_cell + "Traction_force_on_FA" + File.separator + "Regularization_parameter_plot_" + IJ.pad(frame, 2) + ".tif"); } catch (Exception e) { showDialogWithImageAndCustomOkAndNoCancel("Traction force applied on FA", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "Traction_force_on_FA" + File.separator + "Regularization_parameter_plot_" + IJ.pad(frame, 2) + ".tif", "The analysis is stopped at the step \"Traction force applied on FA\""); } lambdaPlotImp .close(); lambda = lambda_v.get( calculateRhoOpt( rho ) ); // IJ.log( "Value = " + lambda ); // calculateAndPlotForces IJ.showStatus("Solving inverse problem..."); tikhonovVal(lambda, V, zeta, s, FX, FY); // saveFittingParametersData try { FileWriter fstream = new FileWriter(folder_cell + "Traction_force_on_FA" + File.separator + "Fitting_parameters_data_" + IJ.pad(frame, 2) + ".txt"); BufferedWriter fileOutputStream = new BufferedWriter(fstream); fileOutputStream.write( "Beads displacements\t" + "Beads_displacements_" + IJ.pad(frame, 2) + ".txt" + "\n" ); fileOutputStream.write( "FA positions\t" + "FA_positions_" + IJ.pad(frame, 2) + ".txt" + "\n" ); fileOutputStream.write( "image width\t" + image_width + "\n" ); fileOutputStream.write( "image height\t" + image_height + "\n" ); fileOutputStream.write( "Beads positions initial\t" + beads_size_initial + "\n" ); fileOutputStream.write( "FA positions initial\t" + FA_size_initial + "\n" ); fileOutputStream.write( "Displacements smaller than value set to zero\t" + delta2 + "\n" ); fileOutputStream.write( "Maximal displacement\t" + displacement_maximum + "\n" ); fileOutputStream.write( "Found at position\t" + (displacement_maximum_index + 1) + "\n" ); fileOutputStream.write( "Minimum distance focals - displacements required (pixels)\t" + delta1 + "\n" ); fileOutputStream.write( "Maximal distance focals - displacements allowed (pixels)\t" + delta3 + "\n" ); fileOutputStream.write( "Displacements deleted\t" + delLines + "\n" ); fileOutputStream.write( "Displacements left\t" + beads1X.size() + "\n" ); fileOutputStream.write( "Displacements set to zero\t" + iset + "\n" ); fileOutputStream.write( "Displacements left unchanged\t" + (beads1X.size() - iset) + "\n" ); fileOutputStream.write( "Number of degrees of freedom\t" + DF + "\n" ); fileOutputStream.write( "Sigma\t" + sigma + "\n" ); fileOutputStream.write( "Optimal rho\t" + rho_opt + "\n" ); fileOutputStream.write( "Regularization parameter\t" + lambda + "\n\n\n" ); fileOutputStream.write( "focalsX (pixel)\tfocalsY (pixel)\tFX (pixel)\tFY (pixel)\tFX (nN)\tFY (nN)\tForce (nN)\n" ); for(i = 0; i < FX.size(); i++) fileOutputStream.write( String.valueOf(focalsX.get(i)) + "\t" + String.valueOf(focalsY.get(i)) + "\t" + String.valueOf(FX.get(i)) + "\t" + String.valueOf(FY.get(i)) + "\t" + String.valueOf(conversionFactor * FX.get(i)) + "\t" + String.valueOf(conversionFactor * FY.get(i)) + "\t" + String.valueOf(conversionFactor * Math.sqrt(Math.pow(FX.get(i), 2) + Math.pow(FY.get(i), 2)) ) + "\n" ); fileOutputStream.close(); } catch (Exception e) { showDialogWithImageAndCustomOkAndNoCancel("Traction force applied on FA", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "Traction_force_on_FA" + File.separator + "Fitting_parameters_data_" + IJ.pad(frame, 2) + ".txt", "The analysis is stopped at the step \"Traction force applied on FA\""); } for(i = 0; i < FX.size(); i++) { FX.set(i, scale * FX.get(i) + focalsX.get(i)); FY.set(i, scale * FY.get(i) + focalsY.get(i)); } forcePlot = new Plot ("Calculated forces for a regularization parameter of " + lambda + " and scaling of " + scale, "X Axis", "Y Axis"); forcePlot .setLimits (0., image_width, 0., image_height); // forcePlot .show (); Rectangle forcePlotDrawingFrame = forcePlot.getDrawingFrame(); Dimension forcePlotSize = forcePlot.getSize(); forcePlot .setSize (forcePlotSize.width + (image_width - forcePlotDrawingFrame.width), forcePlotSize.height + (image_height - forcePlotDrawingFrame.height)); // forcePlot .update (); forcePlot .setColor (Color.red); forcePlot .setLineWidth (2); forcePlot .addPoints (focalsX, focalsY, Plot.BOX); forcePlot .setColor (Color.blue); forcePlot .setLineWidth (1); forcePlot .drawVectors (focalsX, focalsY, FX, FY); forcePlot .show (); forcePlotImp = forcePlot.getImagePlus(); // plotScaleBar Calibration forcePlotCalibration = new Calibration(); forcePlotCalibration .pixelWidth = length_scale; forcePlotCalibration .pixelHeight = scale / conversionFactor; forcePlotCalibration .setXUnit ( "\u00B5m" ); forcePlotCalibration .setYUnit ( "nN" ); // forcePlotImp .setGlobalCalibration (forcePlotCalibration); forcePlotImp .setCalibration (forcePlotCalibration); IJ.run(forcePlotImp, "Scale Bar...", "width=10 height=1 thickness=4 font=16 color=Blue background=None location=[Upper Right] horizontal vertical bold overlay"); /* forcePlotCalibration .pixelWidth = length_scale; forcePlotCalibration .pixelHeight = length_scale; forcePlotCalibration .setXUnit ( "\u00B5m"); forcePlotCalibration .setYUnit ( "\u00B5m"); forcePlotImp .setCalibration (forcePlotCalibration); */ forcePlot .setFrozen (true); try { IJ .saveAsTiff (forcePlotImp, folder_cell + "Traction_force_on_FA" + File.separator + "Force_plot_" + IJ.pad(frame, 2) + ".tif"); } catch (Exception e) { showDialogWithImageAndCustomOkAndNoCancel("Traction force applied on FA", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "Traction_force_on_FA" + File.separator + "Force_plot_" + IJ.pad(frame, 2) + ".tif", "The analysis is stopped at the step \"Traction force applied on FA\""); } // imp .copy (); // forcePlot .setFrozen (true); forcePlotDrawingFrame = forcePlot.getDrawingFrame(); forcePlotImp .paste (forcePlotDrawingFrame.x, forcePlotDrawingFrame.y, "XOR"); forcePlot .update (); try { IJ .saveAsTiff (forcePlotImp, folder_cell + "Traction_force_on_FA" + File.separator + "Force_plot_with_image_" + IJ.pad(frame, 2) + ".tif"); } catch (Exception e) { showDialogWithImageAndCustomOkAndNoCancel("Traction force applied on FA", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folder_cell + "Traction_force_on_FA" + File.separator + "Force_plot_with_image_" + IJ.pad(frame, 2) + ".tif", "The analysis is stopped at the step \"Traction force applied on FA\""); } // beadsPlotImp .close(); forcePlotImp .close(); imp .close(); /* plotData("Calculated forces for a regularization parameter of " + lambda + " and scaling of " + scale, focalsX, focalsY, FX, FY, focalsX, focalsY); plotScaleBar(); plotForceScaleBar(); */ IJ.showStatus("Done..."); } } // updating and saving "JEasyTFM_x_end.txt" file if(traction_applied_on_FA_starting_folder < traction_applied_on_FA_ending_folder) traction_applied_on_FA_starting_folder++; else { traction_force_applied_on_FA = false; traction_applied_on_FA_starting_folder = 1; } saveJob(folder + "Jobs" + File.separator + "JEasyTFM_" + job_index + "_end.txt"); } // traction_force_applied_on_FA /*****************************************************************************************************************************/ /* FUNCTIONS */ /*****************************************************************************************************************************/ private ImagePlus checkScale(String path) { ImagePlus imp = null; ImagePlus imp1 = null; ImagePlus imp2 = null; Calibration cal; String metadata = null; String[] metadataSub; String[] ImageDescription; double nbDecimals = 10000000d; int dimSlices, dimSlices1, dimSlices2, dimFrames1; int [] dim; int i; // IJ.run("Bio-Formats Importer", "open=[" + path + "] color_mode=Default view=Hyperstack stack_order=XYCZT"); // imp = IJ.getImage(); imp = IJ.openImage(path); if(imp == null) { imp2 = IJ.openImage(path.substring(0, path.length() - 4) + "_p2.tif"); // imp2 .show(); if(imp2 == null) return null; else { dim = imp2.getDimensions(); dimSlices2 = dim[3]; // IJ .run("Bio-Formats Importer", "open=[" + path.substring(0, path.length() - 4) + "_p1.tif" + "] color_mode=Default view=[Standard ImageJ] stack_order=Default"); // imp1 = IJ.getImage(); // cal = imp1.getCalibration(); imp1 = IJ.openImage(path.substring(0, path.length() - 4) + "_p1.tif"); if(imp1 == null) { imp2 .close(); return null; } else { metadata = (String)imp1.getProperty("Info"); if(ch1 && ch2) { dim = imp1.getDimensions(); dimSlices1 = dim[3]; dimFrames1 = dim[4]; dimSlices = (dimFrames1 * dimSlices1) - dimSlices2; IJ .run("Make Substack...", " slices=1-" + dimSlices); imp1 .close(); imp1 = IJ.getImage(); } imp = Concatenator.run(imp1, imp2); imp .show(); imp1 .close(); imp2 .close(); } } } else { imp .show(); metadata = (String) imp.getProperty("Info"); } // cal = imp.getCalibration(); if(metadata != null) { metadataSub = metadata .split("\t\n\r"); ImageDescription = metadataSub[0].split(" "); for(i = 0; i != ImageDescription.length; i++) { if(ImageDescription[i].startsWith("PhysicalSizeX")) { if(Math.round(length_scale * nbDecimals) / nbDecimals != Double.valueOf(ImageDescription[i].substring(15, ImageDescription[i].length() - 1)) ) showDialog("Error on width scaling!!!" , "Beware!!! the width scaling value of the image is not " + String.valueOf(Math.round(length_scale * nbDecimals) / nbDecimals) + ", but " + ImageDescription[i].substring(15, ImageDescription[i].length() - 1)); } if(ImageDescription[i].startsWith("PhysicalSizeY")) { if(Math.round(length_scale * nbDecimals) / nbDecimals != Double.valueOf(ImageDescription[i].substring(15, ImageDescription[i].length() - 1)) ) showDialog("Error on width scaling!!!" , "Beware!!! the width scaling value of the image is not " + String.valueOf(Math.round(length_scale * nbDecimals) / nbDecimals) + ", but " + ImageDescription[i].substring(15, ImageDescription[i].length() - 1)); return imp; } } } /* if(Math.round(length_scale * nbDecimals) / nbDecimals != cal.pixelHeight) showDialog("Error on width scaling!!!" , "Beware!!! the height scaling value of the image is not " + String.valueOf(Math.round(length_scale * nbDecimals) / nbDecimals) + ", but " + String.valueOf(cal.pixelWidth)); if(Math.round(length_scale * nbDecimals) / nbDecimals != cal.pixelWidth ) showDialog("Error on width scaling!!!" , "Beware!!! the width scaling value of the image is not " + String.valueOf(Math.round(length_scale * nbDecimals) / nbDecimals) + ", but " + String.valueOf(cal.pixelWidth)); if(length_unit != cal.getUnit() ) showDialog("Error on scaling unit!!!" , "Beware!!! the scaling unit of the image is not " + length_unit + ", but " + cal.getUnit()); */ return imp; } private ImagePlus openStealth(String path) { ImagePlus imp = null; ImagePlus imp1 = null; ImagePlus imp2 = null; ImagePlus imp3 = null; imp = IJ.openImage(path); if(imp == null) { imp1 = IJ.openImage(path.substring(0, path.length() - 4) + "_p1.tif"); imp2 = IJ.openImage(path.substring(0, path.length() - 4) + "_p2.tif"); imp3 = IJ.openImage(path.substring(0, path.length() - 4) + "_p3.tif"); if(imp1 != null && imp2 != null) { if(imp3 != null) { imp = Concatenator.run(imp1, imp2, imp3); imp3.close(); } else imp = Concatenator.run(imp1, imp2); // imp .show(); imp1.close(); imp2.close(); } } return imp; } private void showDialog(String title, String text) { GenericDialog gd; gd = new GenericDialog(title); gd.addMessage(text); gd.showDialog(); } private void showDialogWithCustomOkAndNoCancel(String title, String text, String text_for_ok_button) { GenericDialog gd; gd = new GenericDialog(title); gd.addMessage(text); gd.setOKLabel(text_for_ok_button); gd.hideCancelButton(); gd.showDialog(); } private void showDialogWithImageAndCustomOkAndNoCancel(String title, String imagePath, String text, String text_for_ok_button) // private void showDialogWithImageAndCustomOkAndNoCancel(String title, String text , String text_for_ok_button) { GenericDialog gd; URL url = null; Image image; ImagePlus icon; String str; gd = new GenericDialog(title); try { url = getClass().getResource("/image/" + imagePath); image = Toolkit.getDefaultToolkit().getImage(url); icon = new ImagePlus("Error message", image); gd .addImage(icon); } catch (Exception e) { str = e.getMessage(); if (str == null || str.equals("")) str = "" + e; IJ.showMessage("Loading the error message image", str + "\n \n" + url); } gd.addToSameRow(); gd.addMessage(text); gd.setOKLabel(text_for_ok_button); gd.hideCancelButton(); gd.showDialog(); } private ImagePlus FlatStack_old(ImagePlus image) { ImagePlus imp; ImageConverter converter; Color color; RoiManager rm; int i; color = Color.yellow; IJ .setForegroundColor(color.getRed(), color.getGreen(), color.getBlue()); rm = RoiManager.getInstance(); // if(rm == null) rm = new RoiManager(); imp = image; for (i = 0; i != rm.getCount(); i++) { rm.runCommand (image, "Deselect"); image .setSlice(i + 1); IJ.run (image, "Select None", ""); imp = image.crop(); converter = new ImageConverter(imp); converter .convertToRGB(); imp.show(); rm.select (i); IJ.run (imp, "Draw", "slice"); imp.setTitle ("Flat-" + i); // imp.show(); } IJ.run(imp, "Images to Stack", "name=" + image.getTitle() + "_Overlay title=Flat"); return IJ.getImage(); } public void copyFile(File in, File out) throws Exception { FileInputStream fis = new FileInputStream(in); FileOutputStream fos = new FileOutputStream(out); try { byte[] buf = new byte[1024]; int i = 0; while((i = fis.read(buf)) != -1) { fos.write(buf, 0, i); } } catch (IOException e) { IJ.log("File open error \n\"" + e.getMessage() + "\"\n"); return; } finally { if (fis != null) fis.close(); if (fos != null) fos.close(); } } private void FlatStack(ImagePlus image) { ImageConverter converter; Color color; RoiManager rm; int i; color = Color.yellow; IJ .setForegroundColor(color.getRed(), color.getGreen(), color.getBlue()); IJ .selectWindow(image.getTitle()); converter = new ImageConverter(image); converter .convertToRGB(); rm = RoiManager.getInstance(); // if(rm == null) rm = new RoiManager(); for (i = 0; i != rm.getCount(); i++) { image .setSlice(i + 1); rm.select (i); IJ.run (image, "Draw", "slice"); } image .setSlice(1); IJ.run (image, "Select None", ""); } private boolean checkAndCreateFolder(String myDir) { File file = new File(myDir); if (!file.exists()) file.mkdir(); file = new File(myDir); if (!file.exists()) { showDialogWithImageAndCustomOkAndNoCancel("Create directory", "writing.png", "Unable to create directory\n \n" + myDir, "The directoy was not created"); return false; } else return true; } private void closeWindow(String window) { if (WindowManager.getWindow(window) != null) { IJ.selectWindow(window); IJ.run("Close"); } } private void closeWindows() { int i; String [] windows = {"Log", "Threshold", "Exception", "B&C", "Channels", "Results"}; for(i = 0; i != windows.length; i++) { if (WindowManager.getWindow(windows[i]) != null) { IJ.selectWindow(windows[i]); IJ.run("Close"); } } } private void Brightness(ImagePlus image, int value) { int i; int dimWidth, dimHeight, dimChannels, dimSlices, dimFrames; int posChannel , posSlice , posFrame ; int [] dim; dim = image.getDimensions(); dimWidth = dim[0]; dimHeight = dim[1]; dimChannels = dim[2]; dimSlices = dim[3]; dimFrames = dim[4]; posChannel = image.getChannel(); posSlice = image.getSlice(); posFrame = image.getFrame(); if(dimChannels != 1) { for(i = 1; i <= dimChannels; i++) { image.setPosition(i, posSlice, posFrame); IJ.run(image, "Enhance Contrast", "saturated=" + value); image.setPosition(posChannel, posSlice, posFrame); } } else IJ.run(image, "Enhance Contrast", "saturated=" + value); } private void biggestParticule(ImagePlus image, int value) { RoiManager rm; IJ.run(image, "Analyze Particles...", "size=" + value + "-Infinity pixel clear add"); rm = RoiManager.getInstance(); if(rm == null) rm = new RoiManager(); if(rm.getCount() > 1) biggestROI(image, rm); rm.select (0); IJ.run (image, "Make Inverse" , ""); IJ.run (image, "Set..." , "value=0"); rm.runCommand (image, "Deselect"); IJ.run (image, "Select None" , ""); } private void biggestROI(ImagePlus image, RoiManager rm) { ImageStatistics stats; ImageProcessor ip; Roi roi; int i; int ROISize, ROIcount, BigestROI, BigestOne; ROIcount = rm.getCount(); BigestROI = 0; BigestOne = 0; ip = image.getProcessor(); for(i = 0; i != ROIcount; i++) { rm.select (i); roi = image.getRoi(); ip .setRoi(roi); stats = ImageStatistics.getStatistics(ip, Measurements.AREA, null); ROISize = (int) Math.round(stats.area); if(ROISize > BigestROI) { BigestROI = ROISize; BigestOne = i; } } rm.select (BigestOne); rm.reset (); rm.addRoi (image.getRoi()); } private String [] split(String s1, String s2) { String [] strings = null; if (s1.length() > 0 && s2 != null && (s2.equals(",") || s2.equals(";"))) strings = s1.split(s2, -1); else if (s1.length() > 0 && s2 != null && s2.length() >= 3 && s2.startsWith("(") && s2.endsWith(")")) { s2 = s2.substring(1, s2.length() - 1); strings = s1.split(s2, -1); } else strings = (s2 == null || s2.equals("")) ? Tools.split(s1) : Tools.split(s1, s2); return strings; } private int getPositionX1(ImagePlus image) { for(int j = 0; j != image.getWidth(); j++) if(image.getProcessor().getPixel(j, Math.round(image.getHeight() / 2)) != 0) return j; return 0; } private int getPositionX2(ImagePlus image) { for(int j = image.getWidth() - 1; j >= 0; j--) if(image.getProcessor().getPixel(j, Math.round(image.getHeight() / 2)) != 0) return j; return 0; } private int getPositionY1(ImagePlus image) { for(int j = 0; j != image.getHeight(); j++) if(image.getProcessor().getPixel(Math.round(image.getWidth() / 2), j) != 0) return j; return 0; } private int getPositionY2(ImagePlus image) { for(int j = image.getHeight() - 1; j >= 0; j--) if(image.getProcessor().getPixel(Math.round(image.getWidth() / 2), j) != 0) return j; return 0; } private int [] KurtFocus(ImagePlus image) { ImagePlus image2; ResultsTable rt; int index; int frame; int bestFocus; // double bestScore; int [] bestFocusArray; IJ.run("Set Measurements...", "kurtosis redirect=None decimal=4"); rt = Analyzer.getResultsTable(); bestFocusArray = new int[frames]; for (index = 0; index != bestFocusArray.length; index++) bestFocusArray[index] = 0; for(frame = frames_begin; frame <= frames; frame++) { IJ.run("Clear Results", ""); image2 = new Duplicator().run(image, 1, 1, 1, slices, frame, frame); IJ.run(image2, "Measure Stack...", "slices order=czt(default)"); rt.sort("Kurt"); // bestScore = rt.getValue("Kurt" , getBestScoreIndexFromPositifMin(rt)); // bestScore = rt.getValue("Kurt" , getBestScoreIndexfromAbs (rt)); // bestScore = rt.getValue("Kurt" , rt.size() - 1); // bestFocus = (int) rt.getValue("Slice", getBestScoreIndexFromPositifMin(rt)); // bestFocus = (int) rt.getValue("Slice", getBestScoreIndexfromAbs (rt)); bestFocus = (int) rt.getValue("Slice", rt.size() - 1); // IJ.log("frame = " + frame + " bestScore = " + bestScore + " bestFocus = " + bestFocus); bestFocusArray[frame - 1] = bestFocus; } TextWindow resultsWindow = (TextWindow) WindowManager.getWindow("Results"); // if (ResultsWindow != null) // { IJ.run("Clear Results"); resultsWindow.close(); // } return bestFocusArray; } private int getBestScoreIndexFromPositifMin(ResultsTable resultsTable) { int index; for (index = 0; index < resultsTable.size(); index++) if (resultsTable.getValue("Kurt" , index) > 0) return index; return resultsTable.size() - 1; } private int getBestScoreIndexfromAbs(ResultsTable resultsTable) { int index, minIndex; double [] values; values = resultsTable.getColumn("Kurt"); minIndex = 0; for (index = 1; index < values.length; index++) if (Math.abs(values[index]) < Math.abs(values[minIndex])) minIndex = index; return minIndex; } private int MaxFocus(ImagePlus image) { ResultsTable rt; int frame, slice; int bestFocus; double bestScore, val; double [] bestScoreArray; IJ.run("Set Measurements...", "min redirect=None decimal=4"); rt = Analyzer.getResultsTable(); bestScoreArray = new double[slices]; for (slice = 0; slice != bestScoreArray.length; slice++) bestScoreArray[slice] = 0.0; for(frame = frames_begin; frame <= frames; frame++) { IJ.run("Clear Results", ""); bestFocus = 1; bestScore = 0.0; for (slice = 1; slice <= slices; slice++) { image.setPosition(1, slice, frame); IJ.run(image, "Measure", ""); val = rt.getValue("Max", slice - 1); if(val > bestScore) { bestScore = val; bestFocus = slice; } } bestScoreArray[bestFocus - 1] += bestScore; } TextWindow resultsWindow = (TextWindow) WindowManager.getWindow("Results"); // if (ResultsWindow != null) // { IJ.run("Clear Results"); resultsWindow.close(); // } RoiManager rm = RoiManager.getInstance(); if(rm != null) rm.close(); bestFocus = 0; bestScore = 0.0; for (slice = 0; slice != bestScoreArray.length; slice++) { if(bestScoreArray[slice] > bestScore) { bestScore = bestScoreArray[slice]; bestFocus = slice; } } return bestFocus + 1; } private int [] displacementCalculation() { int [] delta = new int [2]; int dx1 = getPositionX1(IJ.getImage()); int dx2 = getPositionX2(IJ.getImage()); int dy1 = getPositionY1(IJ.getImage()); int dy2 = getPositionY2(IJ.getImage()); if(dx1 != 0) delta[0] = dx1; else if(dx2 != IJ.getImage().getWidth() - 1) delta[0] = dx2 - IJ.getImage().getWidth() + 1; if(dy1 != 0) // delta[1] = - dy1; !!! modifié du fait de prbs d'alignements pour le Ch1 delta[1] = dy1; else if(dy2 != IJ.getImage().getHeight() - 1) delta[1] = dy2 - IJ.getImage().getHeight() + 1; return delta; } private double getResult(String column, int row) { ResultsTable rt; rt = Analyzer.getResultsTable(); counter = rt.getCounter(); if (row == -1) row = counter - 1; if (row < 0 || row >= counter) IJ.log("Row (" + row + ") out of range"); col = rt.getColumnIndex(column); if (!rt.columnExists(col)) return Double.NaN; else { value = rt.getValueAsDouble(col, row); if (Double.isNaN(value)) { str = rt.getStringValue(col, row); if (str != null && !str.equals("NaN")) value = Tools.parseDouble(str); } } return value; } private double niceNumber(double v) { //the smallest "nice" number >= v. "Nice" numbers are .. 0.5, 1, 2, 5, 10, 20 ... double base = Math.pow(10, Math.floor(Math.log10(v) - 1.e-6)); if (v > 9.0000001 * base) return 10 * base; else if (v > 8.0000001 * base) return 9 * base; else if (v > 7.0000001 * base) return 8 * base; else if (v > 6.0000001 * base) return 7 * base; else if (v > 5.0000001 * base) return 6 * base; else if (v > 4.0000001 * base) return 5 * base; else if (v > 3.0000001 * base) return 4 * base; else if (v > 2.0000001 * base) return 3 * base; else return 2 * base; } private String getFileName(String dir, String file, int cell) { str = "_Cell " + String.valueOf(cell) + "_1.tif"; String [] fileList = getFileList(dir); for(int i = 0; i != fileList.length; i ++) { if(fileList[i].startsWith(file) && fileList[i].endsWith(str)) return fileList[i]; } return ""; } private String [] getFileList(String dir) { File f = new File(dir); if (!f.exists() || !f.isDirectory()) return new String[0]; String [] list = f.list(); if (list == null) return new String[0]; if (System.getProperty("os.name").indexOf("Linux") != -1) ij.util.StringSorter.sort(list); File f2; int hidden = 0; for (int i = 0; i < list.length; i++) { if (list[i].startsWith(".") || list[i].equals("Thumbs.db")) { list[i] = null; hidden++; } else { f2 = new File(dir, list[i]); if (f2.isDirectory()) list[i] = list[i] + "/"; } } int n = list.length - hidden; if (n <= 0) return new String[0]; if (hidden > 0) { String [] list2 = new String[n]; int j = 0; for (int i = 0; i < list.length; i++) { if (list[i]!=null) list2[j++] = list[i]; } list = list2; } String [] array = new String[n]; for (int i = 0; i < n; i++) array[i] = list[i]; return array; } private double runBinarySearch(double xmin, double xmax, double error, String folder, int frame, int widthCorr, int heightCorr) { double min = getScaleValue(xmin, folder, frame, widthCorr, heightCorr); double max = getScaleValue(xmax, folder, frame, widthCorr, heightCorr); double goal = (max - min) / 2.0; while (xmin <= xmax) { double xmid = (xmin + xmax) / 2; if (Math.abs(getScaleValue(xmid, folder, frame, widthCorr, heightCorr) - goal) < error) return xmid; else if (getScaleValue(xmid, folder, frame, widthCorr, heightCorr) < goal) xmin = xmid; else if (getScaleValue(xmid, folder, frame, widthCorr, heightCorr) > goal) xmax = xmid; } return -1.0; } private double getScaleValue(double xpos, String folder, int frame, int widthCorr, int heightCorr) { return FTTC_main.getScaleValue(folder + "Analysis" + File.separator, "Stack_" + IJ.pad(frame, 2) + ".txt", length_scale, 0.5, E, Math.pow(10.0, -xpos), unitIndex, widthCorr, heightCorr, false, false, false, false, false, false, lut); } private double [] get_lambda_values(String lambda_values_file) { double [] values = null; /* file = new File(lambda_values_file); if (!file.exists()) showDialogWithImageAndCustomOkAndNoCancel("Lambda value reading", "writing.png", "Error while reading\n \n" + e.getMessage() + "\n \n" + lambda_values_file, "The analysis is stopped at the step \"Traction force Lambda reading\""); */ try { String str = IJ.openAsString(lambda_values_file); String [] lines = Tools.split(str ,"\n"); String [] columns; values = new double[lines.length - 1]; for(int i = 1; i != lines.length; i++) { columns = Tools.split(lines[i],"\t"); values[i - 1] = Double.valueOf(columns[1]); } } catch (Exception e) { showDialogWithImageAndCustomOkAndNoCancel("Lambda value reading", "writing.png", "Error while reading the file\n\n" + lambda_values_file + "\n\nwith the error\n\n" + e.getMessage(), "The analysis is stopped at the step \"Traction force Lambda values reading\""); } return values; } // private void cellsAndForceImagesSuperposition(int light = u, int cell = v, int bead = w, int frame = i, String folderRoot = folder_cell, String folderIn, String folderOut, String fileType, String fileName, int pasteMode, boolean text, double scaleMax) private void cellsAndForceImagesSuperposition(int light, int cell, int bead, int frame, String folderRoot, String folderIn, String folderOut, String fileName, String fileType, int pasteMode, boolean text, double scaleMax) { DecimalFormat numericFormat = new DecimalFormat("###,###.#"); DecimalFormat decimalFormat1 = new DecimalFormat("#0.00000"); DecimalFormat decimalFormat2 = new DecimalFormat("#0.00"); DecimalFormat decimalFormat3 = new DecimalFormat("0.00E0"); ImagePlus imp1, imp2; int area = 0; double force = 0.0; // double regularization_factor = lambda; String str; // Roi.setPasteMode(Blitter.COPY_ZERO_TRANSPARENT); // Roi.setPasteMode(Blitter.ADD); Roi.setPasteMode(pasteMode); imp1 = imp2 = null; if(beads == 0) { switch (light) { case 0 : imp1 = IJ.openImage(folderRoot + "CorrCells" + File.separator + "CorrCells_" + IJ.pad(frame, 2) + ".tif"); break; case 1 : imp1 = IJ.openImage(folderRoot + "CorrCells" + File.separator + "CorrCells_Ch1_" + IJ.pad(frame, 2) + ".tif"); break; case 2 : imp1 = IJ.openImage(folderRoot + "CorrCells" + File.separator + "CorrCells_Ch2_" + IJ.pad(frame, 2) + ".tif"); break; case 3 : imp1 = IJ.openImage(folderRoot + "CorrCells" + File.separator + "CorrCells_Ch3_" + IJ.pad(frame, 2) + ".tif"); break; default: imp1 = null; break; } } else { switch (light) { case 0 : imp1 = IJ.openImage(folderRoot + "CorrCells_" + bead + File.separator + "CorrCells_" + bead + "_" + IJ.pad(frame, 2) + ".tif"); break; case 1 : imp1 = IJ.openImage(folderRoot + "CorrCells_" + bead + File.separator + "CorrCells_Ch1_" + bead + "_" + IJ.pad(frame, 2) + ".tif"); break; case 2 : imp1 = IJ.openImage(folderRoot + "CorrCells_" + bead + File.separator + "CorrCells_Ch2_" + bead + "_" + IJ.pad(frame, 2) + ".tif"); break; case 3 : imp1 = IJ.openImage(folderRoot + "CorrCells_" + bead + File.separator + "CorrCells_Ch3_" + bead + "_" + IJ.pad(frame, 2) + ".tif"); break; default: imp1 = null; break; } } if (imp1 == null) { if(beads == 0) { switch (light) { case 0: showDialogWithImageAndCustomOkAndNoCancel("Force integration", "undo.png", "The following file:\n\t\n" + folderRoot + "CorrCells" + File.separator + "CorrCells_" + IJ.pad(frame, 2) + ".tif\n\t\ncould not be found", "The analysis is stopped at the step \"force_integration\""); break; case 1: showDialogWithImageAndCustomOkAndNoCancel("Force integration", "undo.png", "The following file:\n\t\n" + folderRoot + "CorrCells" + File.separator + "CorrCells_Ch1_" + IJ.pad(frame, 2) + ".tif\n\t\ncould not be found", "The analysis is stopped at the step \"force_integration\""); break; case 2: showDialogWithImageAndCustomOkAndNoCancel("Force integration", "undo.png", "The following file:\n\t\n" + folderRoot + "CorrCells" + File.separator + "CorrCells_Ch2_" + IJ.pad(frame, 2) + ".tif\n\t\ncould not be found", "The analysis is stopped at the step \"force_integration\""); break; case 3: showDialogWithImageAndCustomOkAndNoCancel("Force integration", "undo.png", "The following file:\n\t\n" + folderRoot + "CorrCells" + File.separator + "CorrCells_Ch3_" + IJ.pad(frame, 2) + ".tif\n\t\ncould not be found", "The analysis is stopped at the step \"force_integration\""); break; } } else { switch (light) { case 0: showDialogWithImageAndCustomOkAndNoCancel("Force integration", "undo.png", "The following file:\n\t\n" + folderRoot + "CorrCells_" + bead + File.separator + "CorrCells_" + bead + "_" + IJ.pad(frame, 2) + ".tif\n\t\ncould not be found", "The analysis is stopped at the step \"force_integration\""); break; case 1: showDialogWithImageAndCustomOkAndNoCancel("Force integration", "undo.png", "The following file:\n\t\n" + folderRoot + "CorrCells_" + bead + File.separator + "CorrCells_Ch1_" + bead + "_" + IJ.pad(frame, 2) + ".tif\n\t\ncould not be found", "The analysis is stopped at the step \"force_integration\""); break; case 2: showDialogWithImageAndCustomOkAndNoCancel("Force integration", "undo.png", "The following file:\n\t\n" + folderRoot + "CorrCells_" + bead + File.separator + "CorrCells_Ch2_" + bead + "_" + IJ.pad(frame, 2) + ".tif\n\t\ncould not be found", "The analysis is stopped at the step \"force_integration\""); break; case 3: showDialogWithImageAndCustomOkAndNoCancel("Force integration", "undo.png", "The following file:\n\t\n" + folderRoot + "CorrCells_" + bead + File.separator + "CorrCells_Ch3_" + bead + "_" + IJ.pad(frame, 2) + ".tif\n\t\ncould not be found", "The analysis is stopped at the step \"force_integration\""); break; } } return; } // imp1.show(); IJ.run(imp1, "Enhance Contrast", "saturated=0.35"); IJ.run(imp1, "RGB Color", ""); if(beads == 0) imp2 = IJ.openImage(folderRoot + folderIn + File.separator + "Traction_" + fileType + "_Plot_Traction_Stack_" + IJ.pad(frame, 2) + ".tif"); else imp2 = IJ.openImage(folderRoot + folderIn + "_" + bead + File.separator + "Traction_" + fileType + "_Plot_Traction_Stack_" + bead + "_" + IJ.pad(frame, 2) + ".tif"); if (imp2 == null) { if(beads == 0) showDialogWithImageAndCustomOkAndNoCancel("Force integration", "undo.png", "The following file:\n\t\n" + folderRoot + folderIn + File.separator + "Traction_" + fileType + "_Plot_Traction_Stack_" + IJ.pad(frame, 2) + ".tif\n\t\ncould not be found", "The analysis is stopped at the step \"force_integration\""); else showDialogWithImageAndCustomOkAndNoCancel("Force integration", "undo.png", "The following file:\n\t\n" + folderRoot + folderIn + "_" + bead + File.separator + "Traction_" + fileType + "_Plot_Traction_Stack_" + bead + "_" + IJ.pad(frame, 2) + ".tif\n\t\ncould not be found", "The analysis is stopped at the step \"force_integration\""); return; } // imp2 .show(); // imp2 .setDisplayRange(0, 1000); IJ .run(imp2, "Select All", ""); IJ .run(imp2, "Copy", ""); imp2 .close(); IJ .run(imp1, "Paste", ""); IJ .run(imp1, "Select None", ""); imp1 .show(); if(text) { Font font = new Font("SansSerif", Font.PLAIN, 20); Font fExp = new Font("SansSerif", Font.BOLD , 15); RoiManager rm = RoiManager.getInstance(); if(rm == null) rm = new RoiManager(); ResultsTable rt = Analyzer.getResultsTable(); rm .select(frame - 1); Color color = Color.yellow; IJ .setForegroundColor(color.getRed(), color.getGreen(), color.getBlue()); IJ .run(imp1, "Draw", "slice"); area = (int) Math.round( rt.getValue("Area" , frame - 1)); force = rt.getValue("IntDen", frame - 1); color = Color.white; IJ .setForegroundColor(color.getRed(), color.getGreen(), color.getBlue()); // str = "Area = " + Integer.toString(area) + " pixels"; // str = "Area = " + Double.toString(area * Math.pow(length_scale, 2.0)) + " \u00B5m^2"; // str = "Area = " + decimalFormat2.format(area * Math.pow(length_scale, 2.0)) + " \u00B5m^2"; str = "Area = " + decimalFormat2.format(area * Math.pow(length_scale, 2.0)) + " \u00B5m"; imp1 .setRoi(new TextRoi( 34, 5, str, font)); IJ .run(imp1, "Draw", "slice"); imp1 .setRoi(new TextRoi( 34 + 2 + imp1.getProcessor().getStringWidth(str), 2, "2", fExp)); IJ .run(imp1, "Draw", "slice"); str = "Force = " + decimalFormat2.format(force * 1.0e-6) + " \u00B5N"; imp1 .setRoi(new TextRoi(280, 5, str, font)); IJ .run(imp1, "Draw", "slice"); // str = "Ratio = " + decimalFormat1.format((double) force / area) + " N/pixels"; // str = "Ratio = " + decimalFormat1.format((double) force / (area * Math.pow(length_scale, 2))) + " N/\u00B5m^2"; // str = "Ratio = " + decimalFormat2.format((double) force / (area * Math.pow(length_scale, 2))) + " N/\u00B5m^2"; str = "Force ratio = " + decimalFormat2.format((double) force / (1.0e3 * area * Math.pow(length_scale, 2))) + " nN/\u00B5m"; imp1 .setRoi(new TextRoi(500, 5, str, font)); IJ .run(imp1, "Draw", "slice"); imp1 .setRoi(new TextRoi(500 + 2 + imp1.getProcessor().getStringWidth(str), 2, "2", fExp)); IJ .run(imp1, "Draw", "slice"); str = "E = " + numericFormat.format(E) + " Pa"; // imp1 .setRoi(new TextRoi(1000, 5, str, font)); imp1 .setRoi(new TextRoi(800, 5, str, font)); IJ .run(imp1, "Draw", "slice"); // str = "lambda = " + decimalFormat3.format(regularization_factor); // str = "\u03BB = " + decimalFormat3.format(regularization_factor); str = "\u03BB = " + decimalFormat3.format(lambda_values[frame - 1]); // imp1 .setRoi(new TextRoi(1000, 5, str, font)); imp1 .setRoi(new TextRoi(imp1.getWidth() - imp1.getProcessor().getStringWidth(str) - 58, 5, str, font)); IJ .run(imp1, "Draw", "slice"); } str = fileType == "Vector" ? "_" + IJ.pad(String.valueOf(FTTC_max_vector_length), 3) : ""; try { if(beads == 0) { switch (light) { case 0: IJ.saveAs(imp1, "Jpeg", folderRoot + folderOut + File.separator + fileName + "_with_Traction_" + fileType + "_Plot_" + IJ.pad(frame, 2) + str + ".jpg"); break; case 1: IJ.saveAs(imp1, "Jpeg", folderRoot + folderOut + File.separator + fileName + "_with_Traction_" + fileType + "_Plot_Ch1_" + IJ.pad(frame, 2) + str + ".jpg"); break; case 2: IJ.saveAs(imp1, "Jpeg", folderRoot + folderOut + File.separator + fileName + "_with_Traction_" + fileType + "_Plot_Ch2_" + IJ.pad(frame, 2) + str + ".jpg"); break; case 3: IJ.saveAs(imp1, "Jpeg", folderRoot + folderOut + File.separator + fileName + "_with_Traction_" + fileType + "_Plot_Ch3_" + IJ.pad(frame, 2) + str + ".jpg"); break; } } else { switch (light) { case 0: IJ.saveAs(imp1, "Jpeg", folderRoot + folderOut + "_" + bead + File.separator + fileName + "_with_Traction_" + fileType + "_Plot_" + bead + "_" + IJ.pad(frame, 2) + str + ".jpg"); break; case 1: IJ.saveAs(imp1, "Jpeg", folderRoot + folderOut + "_" + bead + File.separator + fileName + "_with_Traction_" + fileType + "_Plot_" + bead + "_Ch1_" + IJ.pad(frame, 2) + str + ".jpg"); break; case 2: IJ.saveAs(imp1, "Jpeg", folderRoot + folderOut + "_" + bead + File.separator + fileName + "_with_Traction_" + fileType + "_Plot_" + bead + "_Ch2_" + IJ.pad(frame, 2) + str + ".jpg"); break; case 3: IJ.saveAs(imp1, "Jpeg", folderRoot + folderOut + "_" + bead + File.separator + fileName + "_with_Traction_" + fileType + "_Plot_" + bead + "_Ch3_" + IJ.pad(frame, 2) + str + ".jpg"); break; } } } catch (Exception e) { if(beads == 0) { switch (light) { case 0: showDialogWithImageAndCustomOkAndNoCancel("Force integration", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folderRoot + folderOut + File.separator + fileName + "_with_Traction_" + fileType + "_Plot_" + IJ.pad(frame, 2) + ".jpg", "The analysis is stopped at the step \"force_integration\""); break; case 1: showDialogWithImageAndCustomOkAndNoCancel("Force integration", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folderRoot + folderOut + File.separator + fileName + "_with_Traction_" + fileType + "_Plot_Ch1_" + IJ.pad(frame, 2) + ".jpg", "The analysis is stopped at the step \"force_integration\""); break; case 2: showDialogWithImageAndCustomOkAndNoCancel("Force integration", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folderRoot + folderOut + File.separator + fileName + "_with_Traction_" + fileType + "_Plot_Ch2_" + IJ.pad(frame, 2) + ".jpg", "The analysis is stopped at the step \"force_integration\""); break; case 3: showDialogWithImageAndCustomOkAndNoCancel("Force integration", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folderRoot + folderOut + File.separator + fileName + "_with_Traction_" + fileType + "_Plot_Ch3_" + IJ.pad(frame, 2) + ".jpg", "The analysis is stopped at the step \"force_integration\""); break; } } else { switch (light) { case 0: showDialogWithImageAndCustomOkAndNoCancel("Force integration", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folderRoot + folderOut + "_" + bead + File.separator + fileName + "_with_Traction_" + fileType + "_Plot_" + bead + "_" + IJ.pad(frame, 2) + ".jpg", "The analysis is stopped at the step \"force_integration\""); break; case 1: showDialogWithImageAndCustomOkAndNoCancel("Force integration", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folderRoot + folderOut + "_" + bead + File.separator + fileName + "_with_Traction_" + fileType + "_Plot_" + bead + "_Ch1_" + IJ.pad(frame, 2) + ".jpg", "The analysis is stopped at the step \"force_integration\""); break; case 2: showDialogWithImageAndCustomOkAndNoCancel("Force integration", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folderRoot + folderOut + "_" + bead + File.separator + fileName + "_with_Traction_" + fileType + "_Plot_" + bead + "_Ch2_" + IJ.pad(frame, 2) + ".jpg", "The analysis is stopped at the step \"force_integration\""); break; case 3: showDialogWithImageAndCustomOkAndNoCancel("Force integration", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folderRoot + folderOut + "_" + bead + File.separator + fileName + "_with_Traction_" + fileType + "_Plot_" + bead + "_Ch3_" + IJ.pad(frame, 2) + ".jpg", "The analysis is stopped at the step \"force_integration\""); break; } } return; } IJ.run("Close"); // imp1.close(); if(text) { file = new File(folderRoot + folderOut + ".txt"); if (!file.exists()) { try { FileOutputStream fos = new FileOutputStream (folderRoot + folderOut + ".txt"); BufferedOutputStream bos = new BufferedOutputStream (fos); PrintWriter writer = new PrintWriter (bos, true); writer .println("Cell\tFrame\tArea (pixel)\tArea (\u00B5m^2)\tForce (pN)\tForce ratio (pN/\u00B5m^2)\tForce (pPa)\tForce ratio (pPa/\u00B5m^2)\tLambda (-)\tscaleMax (pPa)"); writer .println("Cell " + Integer.toString(cell) + "\t" + Integer.toString(frame) + "\t" + Integer.toString(area) + "\t" + decimalFormat2.format(area * Math.pow(length_scale, 2.0)) + "\t" + decimalFormat2.format(force) + "\t" + decimalFormat2.format((double) force / (area * Math.pow(length_scale, 2))) + "\t" + decimalFormat2.format(force / window_area) + "\t" + decimalFormat2.format((double) force / (window_area * area * Math.pow(length_scale, 2))) + "\t" + decimalFormat3.format(lambda_values[frame - 1]) + "\t" + String.valueOf(scaleMax)); writer .close(); } catch (IOException e) { IJ.log("File open error \n\"" + e.getMessage() + "\"\n"); showDialogWithImageAndCustomOkAndNoCancel("Force integration", "writing.png", "Error while writing\n \n" + e.getMessage() + "\n \n" + folderRoot + folderOut + ".txt", "The analysis is stopped at the step \"force_integration\""); return; } } else { IJ.append("Cell " + Integer.toString(cell) + "\t" + Integer.toString(frame) + "\t" + Integer.toString(area) + "\t" + decimalFormat2.format(area * Math.pow(length_scale, 2.0)) + "\t" + decimalFormat2.format(force) + "\t" + decimalFormat2.format((double) force / (area * Math.pow(length_scale, 2))) + "\t" + decimalFormat2.format(force / window_area) + "\t" + decimalFormat2.format((double) force / (window_area * area * Math.pow(length_scale, 2))) + "\t" + decimalFormat3.format(lambda_values[frame - 1]) + "\t" + String.valueOf(scaleMax), folderRoot + folderOut + ".txt"); } } } public double getDistance(double x1, double x2, double y1, double y2) { return Math.sqrt( Math.pow(x2 - x1, 2.0) + Math.pow(y2 - y1, 2.0) ); } public double calcultateU(int index, ArrayList beads1X, ArrayList beads1Y, ArrayList beads2X, ArrayList beads2Y) { int index2 = index / 2; if(index == 2 * index2) return beads2X.get(index2) - beads1X.get(index2); else return beads2Y.get(index2) - beads1Y.get(index2); } public double Greens(int indexI, int indexJ, ArrayList focalsX, ArrayList focalsY, ArrayList beads1X, ArrayList beads1Y) { int indexI2 = indexI / 2; int indexJ2 = indexJ / 2; double mag = Math.sqrt( Math.pow(beads1X.get(indexI2) - focalsX.get(indexJ2), 2.0) + Math.pow(beads1Y.get(indexI2) - focalsY.get(indexJ2), 2.0) ); if(indexI == 2 * indexI2) if(indexJ == 2 * indexJ2) return 3.0 / ( 4.0 * Math.PI * mag ) * ( 1.0 + Math.pow( ( beads1X.get(indexI2) - focalsX.get(indexJ2) ) / mag, 2.0) ); else return 3.0 / ( 4.0 * Math.PI * Math.pow(mag, 3.0) ) * ( beads1X.get(indexI2) - focalsX.get(indexJ2) ) * ( beads1Y.get(indexI2) - focalsY.get(indexJ2) ); else if(indexJ == 2 * indexJ2) return 3.0 / ( 4.0 * Math.PI * Math.pow(mag, 3.0) ) * ( beads1X.get(indexI2) - focalsX.get(indexJ2) ) * ( beads1Y.get(indexI2) - focalsY.get(indexJ2) ); else return 3.0 / ( 4.0 * Math.PI * mag ) * ( 1.0 + Math.pow( ( beads1Y.get(indexI2) - focalsY.get(indexJ2) ) / mag, 2.0) ); } public void tikhonovVect(RealMatrix U, ArrayList s, RealMatrix V, ArrayList b, ArrayList lambda, ArrayList beta, ArrayList zeta, ArrayList eta, ArrayList rho) { // TIKHONOV Tikhonov regularization. // [x_lambda,rho,eta] = tikhonov(U,s,V,b,lambda,x_0) // [x_lambda,rho,eta] = tikhonov(U,sm,X,b,lambda,x_0) , sm = [sigma,mu] // Computes the Tikhonov regularized solution x_lambda. If the SVD // is used, i.e. if U, s, and V are specified, then standard-form // regularization is applied: // min { || A x - b ||^2 + lambda^2 || x - x_0 ||^2 } . // If, on the other hand, the GSVD is used, i.e. if U, sm, and X are // specified, then general-form regularization is applied: // min { || A x - b ||^2 + lambda^2 || L (x - x_0) ||^2 } . // If x_0 is not specified, then x_0 = 0 is used // Note that x_0 cannot be used if A is underdetermined and L ~= I. // If lambda is a vector, then x_lambda is a matrix such that // x_lambda = [ x_lambda(1), x_lambda(2), ... ] . // The solution norm (standard-form case) or seminorm (general-form // case) and the residual norm are returned in eta and rho. // Per Christian Hansen, IMM, April 14, 2003. // Reference: A. N. Tikhonov & V. Y. Arsenin, "Solutions of // Ill-Posed Problems", Wiley, 1977. // Initialization. if (minima(lambda) < 0) IJ.showMessage("Illegal regularization parameter lambda"); int i, j, k; // int m = U.getRowDimension(); // int n = V.getRowDimension(); // int p = s.size(); // int ps = 1; double val1, val2; // beta = U(:,1:p)'*b; beta.clear(); for(i = 0; i < U.getColumnDimension(); i++) { val1 = 0.0; for(j = 0; j < b.size(); j++) val1 += U.getEntry(j, i) * b.get(j); beta.add( val1 ); } // zeta = s(:,1).*beta; zeta.clear(); for(i = 0; i < s.size(); i++) zeta.add( s.get(i) * beta.get(i) ); // int ll = lambda.size(); RealMatrix x_lambda = MatrixUtils.createRealMatrix( V.getRowDimension(), lambda.size() ); rho.clear(); // eta.clear(); // The standard-form case. // x_lambda(:,i) = V(:,1:p)*(zeta./(s.^2 + lambda(i)^2)); /* for(i = 0; i < x_lambda.getRowDimension(); i++) // 64 { for(j = 0; j < lambda.size(); j++) // 30 { val1 = 0.0; for(k = 0; k < s.size(); k++) // 64 val += V.getEntry(i, k) * zeta.get(k) / ( Math.pow( s.get(k), 2.0) + Math.pow( lambda.get(j), 2.0) ); x_lambda.setEntry( i, j, val ); } } */ // rho(i) = lambda(i)^2*norm(beta./(s.^2 + lambda(i)^2)); // eta(i) = norm(x_lambda(:,i)); for(i = 0; i < lambda.size(); i++) // 30 { val1 = 0.0; for(j = 0; j < s.size(); j++) // 64 val1 += Math.pow( Math.pow( lambda.get(i), 2.0 ) * beta.get(j) / ( Math.pow( s.get(j), 2.0) + Math.pow( lambda.get(i), 2.0) ), 2.0 ); rho.add( Math.sqrt( val1 ) ); /* val1 = 0.0; for(j = 0; j < x_lambda.getRowDimension(); j++) // 64 val1 += Math.pow( x_lambda.getEntry(j, i), 2.0 ); eta.add( Math.sqrt( val1 ) ); */ } if( U.getRowDimension() > s.size() ) { // rho = sqrt(rho.^2 + norm(b - U(:,1:n)*[beta;U(:,p+1:n)'*b])^2); if(U.getColumnDimension() != V.getRowDimension()) IJ.showMessage( "Modification of the code required to add U(:,p+1:n)'*b to [beta;U(:,p+1:n)'*b]" ); val2 = 0.0; for(i = 0; i < U.getRowDimension(); i++) { val1 = 0.0; for(j = 0; j < V.getRowDimension(); j++) val1 += U.getEntry(i , j) * beta.get(j); val1 = b.get(i) - val1; val2 += Math.pow( val1, 2.0 ); } for(i = 0; i < rho.size(); i++) rho.set(i , Math.sqrt( Math.pow(rho.get( i ), 2.0) + val2 ) ); } } public void tikhonovVal(double lambda, RealMatrix V, ArrayList zeta, ArrayList s, ArrayList FX, ArrayList FY) { // Initialization. if (lambda < 0) IJ.showMessage("Illegal regularization parameter lambda"); // The standard-form case. // x_lambda(:,i) = V(:,1:p)*(zeta./(s.^2 + lambda(i)^2)); FX.clear(); FY.clear(); for(int i = 0; i < V.getRowDimension(); i++) // 64 { double val = 0.0; for(int j = 0; j < s.size(); j++) // 64 val += V.getEntry(i, j) * zeta.get(j) / ( Math.pow( s.get(j), 2.0) + Math.pow( lambda, 2.0) ); if( i == 2 * (i / 2) ) FX.add( val ); else FY.add( val ); } } public double minima(ArrayList list) { double val = list.get(0); for(int i = 1; i < list.size(); i++) if(list.get(i) < val) val = list.get(i); return val; } public int calculateRhoOpt(ArrayList array) { int i, j = 0; double val1 = ( array.get( array.size() - 1 ) + array.get( 0 ) ) / 2.0 ; double val2 = Math.abs( val - array.get( 0 ) ); for( i = 1; i < array.size(); i++ ) if( Math.abs( val1 - array.get( i ) ) < val2 ) { val2 = Math.abs( val1 - array.get( i ) ); j = i; } return j; } public double getRhoMinima(ArrayList array) { if(array.size() == 0) return 0.0; else { double val = array.get(0); for(int i = 1; i != array.size(); i++) { if(array.get(i) < val) val = array.get(i); } return val; } } public double getRhoMaxima(ArrayList array) { if(array.size() == 0) return 0.0; else { double val = array.get(0); for(int i = 1; i != array.size(); i++) { if(array.get(i) > val) val = array.get(i); } return val; } } }