def import_multiple_rois(roi_files): rois = [f.getPath() for f in roi_files if f.exists() and f.getName().lower().endswith("roi")] opener = Opener() rm = RoiManager.getRoiManager() if not rm.getInstance(): rm.reset() [rm.addRoi(opener.openRoi(r)) for r in rois]
def normalized_roi_length(roi_path, pixel_scaling, normalization_fn=None): ''' Returns the scaled measure of the input roi performing the normalization function if provided. ''' opener = Opener() roi = opener.openRoi(roi_path) scaled_measure = roi.getLength() / pixel_scaling if callable(normalization_fn): return normalization_fn(scaled_measure) return measure
def batch_profile_from_threshold(batch_parameters): ''' Thresholds the desired channel using the threshold method specified and saves the roi profile in the csv_output. Rois will be set to the width in pixels specified by stroke_width. Provide a batch parameters dict to operate on images. WIP: PUT A BETTER ALGO IN PLACE TO DETERMINE THE CORRECT ROI TO USE. ''' from ij.io import Opener from IBPlib.ij.Utils.Files import buildList opener = Opener() rois_folder, csvs_folder = setup_output_folders(batch_parameters.get("output_folder")) IJ.log("Plotting profiles...") for i, img in enumerate(batch_parameters.get("analysed_images")): progress = "{0}/{1}".format(i+1, len(batch_parameters.get("analysed_images"))) IJ.log("\n# Progress: {0}\n".format(progress)) imp = imageloader(img) #title = os.path.basename(os.path.splitext(img)[0]) title = os.path.basename(img) IJ.log("\nMeasuring -> {0}".format(title)) rois_path_list = buildList(rois_folder, extension=".roi") rois = [opener.openRoi(roi) for roi in rois_path_list if roi.find(title) > 0] if not rois: IJ.log("## No rois found for {0}".format(title)) if not profile_from_threshold(imp, batch_parameters.get("analysis_ch"), rois, batch_parameters.get("stroke_width"), batch_parameters.get("th_method"), csvs_folder): IJ.log("Batch run canceled.") return IJ.log("Done ...") IJ.log("Results stored in '{0}'".format(csvs_folder))
rois_path_list = buildList(rois_folder, extension=".roi") rois = [opener.openRoi(roi) for roi in rois_path_list if roi.find(title) > 0] if not rois: IJ.log("## No rois found for {0}".format(title)) if not profile_from_threshold(imp, batch_parameters.get("analysis_ch"), rois, batch_parameters.get("stroke_width"), batch_parameters.get("th_method"), csvs_folder): IJ.log("Batch run canceled.") return IJ.log("Done ...") IJ.log("Results stored in '{0}'".format(csvs_folder)) if __name__ in ("__builtin__", "__main__"): from ij.io import Opener opener = Opener() roi_path = r"R:\Igor BP\Projects\Let-805\Raw Data\Microscopies\Yokogawa Spinning Disk\let-805(syb381)\L4\63x OIL\let-805 localization data\Reanalysis\rois\C2-1.tif_0.roi" imp = imageloader(r"R:\\Igor BP\\Projects\\Let-805\\Raw Data\\Microscopies\\Yokogawa Spinning Disk\\let-805(syb381)\\L4\\63x OIL\\zprojections\\Stiched\\1.tif") roi = opener.openRoi(roi_path) ch = 1 rois = [roi] output = r"C:\Users\uqibonac\Desktop\test" th_method = "Li" analysis_ch = 2 stroke_width = 5 print("Running ...") print(profile_from_threshold(imp, analysis_ch, rois, stroke_width, th_method, output)) print("Run finished...")