Problem with Create Fix size ROI from barycenter script

Home Forums Scripts Problem with Create Fix size ROI from barycenter script

  • EricD

    Hi All,
    I tried to use the script with an image containing 4 ROI from spot detector.
    but got the message below. I can’t understand the problem.
    Any idea ???

    And also : Is it possible to send images in this new forum ????

    Number of rois: 4
    TypeError: Impossible d’appeler la méthode “doubleValue” de null (script#55)

    Stephane Dallongeville


    Since last version of Icy, you don’t need to pass anymore by a script to do that, you can use the new ‘to Circle’ and ‘to Square’ ROI operations :

    But just in case, here’s the fixed script (i tried to update it on the website but i couldn’t do it for now) :

    // 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 mass
    boxSize = 1
    removePreviousRois = false
    // get the current sequence focused by the user
    sequence = getSequence()
    // check if the sequence exists
    if ( 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 rois
    rois = sequence.getROIs()
    // get the number of rois
    roiCount = rois.size()
    println("Number of rois: " + roiCount)
    // remove all existing ROI if requested
    if (removePreviousRois)
    // cycle over all rois
    for (i = 0; i < roiCount; i++)
    roi = rois.get(i) // get the spot
    x = ROIUtil.computeDescriptor("Mass center X", roi, sequence).doubleValue()
    y = ROIUtil.computeDescriptor("Mass center Y", roi, sequence).doubleValue()
    keepSpot = true
    // filtering
    surface = 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 spots
    xmin = x - boxSize
    ymin = y - boxSize
    xmax = x + boxSize + 1
    ymax = y + boxSize + 1
    // remove spot if mass center too close from borders
    if (xmin < 0) keepSpot = false
    if (ymin < 0) keepSpot = false if (xmax > w) keepSpot = false
    if (ymax > h) keepSpot = false
    if (!keepSpot) continue
    // create the Rectangle ROI
    newRoi = new ROI2DRectangle(xmin, ymin, xmax, ymax)
    // preserve some settings from original ROI
    ROIUtil.copyROIProperties(roi, newRoi, false)
    newRoi.setName(roi.getName() + " - fixed")
    // add the ROI to the sequence

    About inserting image from the forum, you can do it using the toolbar :

    Note that sometime you need to refresh the page to get the toolbar to display (we are working on fixing that).




    Salut Stephane,
    Merci beaucoup !!!!

    Laura Salavessa


    I noticed the script changed slightly when I launched it. Just to be clear, I can now use the ‘to Circle’ and ‘to Square’ ROI operations, choosing the box size, and it will do the same as the previous script (based on the barycenter of the spot) – is that correct?


Viewing 4 posts - 1 through 4 (of 4 total)

The forum ‘Scripts’ is closed to new topics and replies.