Short Description
This script will iterate through all ROIs from the active Sequence and create for each ROI a new fixed size Rectangle ROI which is located at the mass center (barycenter).
Documentation
See description..
Versions
-
Version 3 • Released on: 2019-04-26 11:00:00DownloadDescription:
Fixed some bugs and commented debug info
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091importClass(Packages.icy.roi.ROIUtil)importClass(Packages.icy.roi.ROIDescriptor)importClass(Packages.icy.gui.dialog.MessageDialog)importClass(Packages.icy.sequence.Sequence)importClass(Packages.java.util.ArrayList)importClass(Packages.plugins.fab.spotDetector.detector.UDWTWavelet)importClass(Packages.plugins.kernel.roi.roi2d.ROI2DRectangle)importClass(java.awt.geom.Point2D)// this is the parameters you asked for: considering the center of mass,// the algo will look in a box of side boxSize*2+1 where the center of mass is the center of this box//// for boxSize = 2//// *****// *****// **X**// *****// *****//// with * : pixel considered for Rectangle ROI// X: location of center of massboxSize = 1removePreviousRois = false// get the current sequence focused by the usersequence = getSequence()// check if the sequence existsif ( sequence == null ){MessageDialog.showDialog("Please open an image first", MessageDialog.INFORMATION_MESSAGE);throw "no sequence"; // stops the script and say why}w = sequence.getSizeX()h = sequence.getSizeY()// get all roisrois = sequence.getROIs()// get the number of roisroiCount = rois.size()println("Number of rois: " + roiCount)// remove all existing ROI if requestedif (removePreviousRois)sequence.removeAllROI()// cycle over all roisfor (i = 0; i < roiCount; i++){roi = rois.get(i) // get the spotx = ROIUtil.computeDescriptor("Mass center X", roi, sequence).doubleValue()y = ROIUtil.computeDescriptor("Mass center Y", roi, sequence).doubleValue()keepSpot = true// filteringsurface = ROIUtil.computeDescriptor("Interior", roi, sequence).doubleValue()meanIntensity = ROIUtil.computeDescriptor("Mean intensity", roi.getSubROI(-1, -1, 0), sequence).doubleValue()//// if (surface < 10) keepSpot = false // remove too small spots// if (surface > 60) keepSpot = false // remove too big spots// if (meanIntensity < 100) keepSpot = false // remove too big spotsxmin = x - boxSizeymin = y - boxSizexmax = x + boxSize + 1ymax = y + boxSize + 1// remove spot if mass center too close from bordersif (xmin < 0) keepSpot = falseif (ymin < 0) keepSpot = falseif (xmax > w) keepSpot = falseif (ymax > h) keepSpot = falseif (!keepSpot) continue// create the Rectangle ROInewRoi = new ROI2DRectangle(xmin, ymin, xmax, ymax)// preserve some settings from original ROIROIUtil.copyROIProperties(roi, newRoi, false)newRoi.setName(roi.getName() + " - fixed")// add the ROI to the sequencesequence.addROI(newRoi)} -
Version 2 • Released on: 2016-07-22 17:22:39DownloadDescription:
fixed some bugs.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102importClass(Packages.icy.roi.ROIUtil)importClass(Packages.icy.roi.ROIDescriptor)importClass(Packages.icy.gui.dialog.MessageDialog)importClass(Packages.icy.sequence.Sequence)importClass(Packages.java.util.ArrayList)importClass(Packages.plugins.fab.spotDetector.detector.UDWTWavelet)importClass(Packages.plugins.kernel.roi.roi2d.ROI2DRectangle)importClass(java.awt.geom.Point2D)// this is the parameters you asked for: considering the center of mass,// the algo will look in a box of side boxSize*2+1 where the center of mass is the center of this box//// for boxSize = 2//// *****// *****// **X**// *****// *****//// with * : pixel considered for Rectangle ROI// X: location of center of massboxSize = 1removePreviousRois = false// get the current sequence focused by the usersequence = getSequence()// check if the sequence existsif ( sequence == null ){MessageDialog.showDialog("Please open an image first", MessageDialog.INFORMATION_MESSAGE);throw "no sequence"; // stops the script and say why}w = sequence.getSizeX()h = sequence.getSizeY()// get all roisrois = sequence.getROIs()// get the number of roisroiCount = rois.size()println("Number of rois: " + roiCount)// remove all existing ROI if requestedif (removePreviousRois)sequence.removeAllROI()// cycle over all roisfor (i = 0; i < roiCount; i++){roi = rois.get(i) // get the spotx = ROIUtil.computeDescriptor("MassCenterX", roi, sequence).doubleValue()y = ROIUtil.computeDescriptor("MassCenterY", roi, sequence).doubleValue()surface = ROIUtil.computeDescriptor("Interior", roi, sequence).doubleValue()meanIntensity = ROIUtil.computeDescriptor("MeanIntensity", roi.getSubROI(-1, -1, 0), sequence).doubleValue()keepSpot = true// filtering// if (surface < 10) keepSpot = false // remove too small spots// if (surface > 60) keepSpot = false // remove too big spots// if (meanIntensity < 100) keepSpot = false // remove too big spotsxmin = x - boxSizeymin = y - boxSizexmax = x + boxSize + 1ymax = y + boxSize + 1// remove spot if mass center too close from bordersif (xmin < 0) keepSpot = falseif (ymin < 0) keepSpot = falseif (xmax > w) keepSpot = falseif (ymax > h) keepSpot = falseif (!keepSpot) continue// create the Rectangle ROInewRoi = new ROI2DRectangle(xmin, ymin, xmax, ymax)println(x)println(y)println(xmin)println(ymin)println(xmax)println(ymax)println(newRoi.getBounds2D())// preserve some settings from original ROIpos = roi.getPosition5D()newRoi.setName(roi.getName() + " - fixed")newRoi.setColor(roi.getColor())newRoi.setZ(pos.getZ())newRoi.setT(pos.getT())newRoi.setC(pos.getC())// add the ROI to the sequencesequence.addROI(newRoi)} -
Version 1 • Released on: 2016-07-22 15:28:43DownloadDescription:
initial version
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687importClass(Packages.plugins.adufour.roi.ROIBasicDescriptor)importClass(Packages.icy.roi.ROIUtil)importClass(Packages.icy.roi.ROIDescriptor)importClass(Packages.icy.gui.dialog.MessageDialog)importClass(Packages.icy.sequence.Sequence)importClass(Packages.java.util.ArrayList)importClass(Packages.plugins.fab.spotDetector.detector.UDWTWavelet)importClass(Packages.icy.roi.ROI2DRectangle)importClass(java.awt.geom.Point2D)// this is the parameters you asked for: considering the center of mass,// the algo will look in a box of side boxSize*2+1 where the center of mass is the center of this box//// for boxSize = 2//// *****// *****// **X**// *****// *****//// with * : pixel considered for Rectangle ROI// X: location of center of massboxSize = 2;removePreviousRois = false;// get the current sequence focused by the usersequence = getSequence()// check if the sequence existsif ( sequence == null ){MessageDialog.showDialog("Please open an image first", MessageDialog.INFORMATION_MESSAGE);throw "no sequence"; // stops the script and say why}w = sequence.getSizeX()h = sequence.getSizeY()// get all roisrois = sequence.getROIs()// get the number of roisroiCount = rois.size();println("Number of rois: " + roiCount)// remove all existing ROI if requestedif (removePreviousRois)sequence.removeAllROI()// cycle over all roisfor (i = 0; i < roiCount; i++){roi = rois.get(i) // get the spotx = ROIUtil.computeDescriptor("MassCenterX", roi, sequence)y = ROIUtil.computeDescriptor("MassCenterY", roi, sequence)surface = ROIUtil.computeDescriptor("Interior", roi, sequence)meanIntensity = ROIUtil.computeDescriptor("MeanIntensity", roi.getSubROI(-1, -1, 0), sequence)keepSpot = true// filtering// if (surface < 10) keepSpot = false // remove too small spots// if (surface > 60) keepSpot = false // remove too big spots// if (meanIntensity < 100) keepSpot = false // remove too big spots// remove spot if mass center too close from bordersif (x - (boxSize+1) < 0) keepSpot = falseif (y - (boxSize+1) < 0) keepSpot = falseif (x + (boxSize+1) > w) keepSpot = falseif (y + (boxSize+1) > h) keepSpot = falseif (!keepSpot) continue// create the Rectangle ROInewRoi = new ROI2DRectangle(new Point2D.Double(x - boxSize, y - boxSize),new Point2D.Double(x + boxSize + 1, y + boxSize + 1),false)// preserve some settings from original ROInewRoi.setName(roi.getName() + " - fixed")newRoi.setColor(roi.getColor())// add the ROI to the sequencesequence.addROI(newRoi)}