How to crop multiple selections in an image at a time

classic Classic list List threaded Threaded
3 messages Options
T.
Reply | Threaded
Open this post in threaded view
|

How to crop multiple selections in an image at a time

T.
I want to crop multiple selections (ROIs) from one image at a time and end up
with the individual crop out images. I have a microscopy picture with
several cells on it, I want to select the single cells and then generat
cropped images of the individual cells. So far I used the ROI Manager to
generate multiple selections in one picture. But now, how can I run the
command 'crop' on all the selections at a time, or in serie.... ?
I would be very glad about some help and advice. Thanks a lot.



--
Sent from: http://imagej.1557.x6.nabble.com/

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: How to crop multiple selections in an image at a time

Herbie
Just select a ROI in the Manager and duplicate the image, which results in a
new and small image with the ROI-contents. Looping through the ROIs gives
you all the cells.

Regards

Herbie

::::::::::::::::::::::::::::::::
Am 09.02.18 um 11:39 schrieb T.:
> I want to crop multiple selections (ROIs) from one image at a time and end
> up
> with the individual crop out images. I have a microscopy picture with
> several cells on it, I want to select the single cells and then generat
> cropped images of the individual cells. So far I used the ROI Manager to
> generate multiple selections in one picture. But now, how can I run the
> command 'crop' on all the selections at a time, or in serie.... ?
> I would be very glad about some help and advice. Thanks a lot.



--
Sent from: http://imagej.1557.x6.nabble.com/

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: How to crop multiple selections in an image at a time

Cammer, Michael
In this version, user makes any type of selection (small rectangle, circle, anything) near the center of the cell and adds to the ROI Manager.


Then run the macro.


Perhaps could be written better, but havent looked at code in 7 years as we use it routinely without problems.


// Michael Cammer;    Dec 2011

var clipsize = 150;  // edge size of the box for clipping cells for montage
var snipwindow = -1;
var projectiondepth = 16;  // default depth for projection of variable depth
var tab = " \t";

// Should be updated each time macros are edited
function checkCurrentVersion(){
  requires('1.51e');
}



//=============================================================================
//  calls function clipCellAndPopOnStack(original, clipstack);
//
macro "clip all ROIs in Roi Manager, center, and put in stack for montage [F4]" {
  original = getImageID;
  t = getTitle;
  bits = bitDepth();
  if (bits == 24) bitstring="RGB";
  else bitstring = ""+bits+"-bit";
  clipsize = getNumber("Enter side of square box in pixels: ", clipsize);
  setPasteMode("Copy");
  setBatchMode(true);
  newImage("snippedstack "+ t, bitstring+" Black", clipsize, clipsize, 1);
  clipstack = getImageID;
  for (i=0;  i<roiManager("count");  i++){
    selectImage(original);
    roiManager("select", i);
    clipCellAndPopOnStack(original, clipstack);
  }  // for  i
  selectImage(clipstack);
  run("Delete Slice");
  run("Select None");
  setBatchMode(false);
  resetMinAndMax();
}  // macro "clip multiple ROIs in a stack and put in stack for montage"



//=======================================================================
// The ROI of the cell is selected and the original image is active before this function is called.
//  clipstack contains the imageID of the clipped stacks window.
//=======================================================================
function clipCellAndPopOnStack(original, clipstack) {
  requires("1.45m");
  run("Set Scale...", "distance=1 known=1 pixel=1 unit=px");
  run("Set Measurements...", "  centroid area redirect=None decimal=0");
  run("Measure");
  xc = getResult("X", nResults-1);
  yc = getResult("Y", nResults-1);
  selectWindow("Results");
  run("Close");
  selectImage(original);
  makeRectangle(xc-(clipsize/2), yc-(clipsize/2), clipsize, clipsize);
  run("Copy");
  run("Select None");
  setPasteMode("Copy");
  selectImage(clipstack);
  run("Paste");
  run("Add Slice");
}  // clip cell





Michael Cammer, Sr Research Scientist, DART Microscopy Laboratory

NYU Langone Health, 540 First Avenue, SK2 Microscopy Suite, New York, NY  10016

C: 914-309-3270  [hidden email]<mailto:[hidden email]>    http://microscopynotes.com/   https://<https://med.nyu.edu/research/research-resources/scientific-cores-shared-resources/microscopy-laboratory>nyulmc.org/micros<https://med.nyu.edu/research/research-resources/scientific-cores-shared-resources/microscopy-laboratory>



________________________________
From: Herbie <[hidden email]>
Sent: Friday, February 9, 2018 6:07:08 AM
To: [hidden email]
Subject: Re: How to crop multiple selections in an image at a time

Just select a ROI in the Manager and duplicate the image, which results in a
new and small image with the ROI-contents. Looping through the ROIs gives
you all the cells.

Regards

Herbie

::::::::::::::::::::::::::::::::
Am 09.02.18 um 11:39 schrieb T.:
> I want to crop multiple selections (ROIs) from one image at a time and end
> up
> with the individual crop out images. I have a microscopy picture with
> several cells on it, I want to select the single cells and then generat
> cropped images of the individual cells. So far I used the ROI Manager to
> generate multiple selections in one picture. But now, how can I run the
> command 'crop' on all the selections at a time, or in serie.... ?
> I would be very glad about some help and advice. Thanks a lot.



--
Sent from: https://urldefense.proofpoint.com/v2/url?u=http-3A__imagej.1557.x6.nabble.com_&d=DwICAg&c=j5oPpO0eBH1iio48DtsedbOBGmuw5jHLjgvtN2r4ehE&r=oU_05LztNstAydlbm5L5GDu_vAdjXk3frDLx_CqKkuo&m=HmsOldtwVox73BqXRxx6pzJM5E9Ju1PWSIGZxdrJhZ8&s=AVHDEOBgEJ246Nj3QSEsWugVER3UzdmmDS4ynj94kxg&e=

--
ImageJ mailing list: https://urldefense.proofpoint.com/v2/url?u=http-3A__imagej.nih.gov_ij_list.html&d=DwICAg&c=j5oPpO0eBH1iio48DtsedbOBGmuw5jHLjgvtN2r4ehE&r=oU_05LztNstAydlbm5L5GDu_vAdjXk3frDLx_CqKkuo&m=HmsOldtwVox73BqXRxx6pzJM5E9Ju1PWSIGZxdrJhZ8&s=H9A3VTXy-b2sn_N4w8jL6BjLOagXdIunWOPD0hiX3gs&e=

------------------------------------------------------------
This email message, including any attachments, is for the sole use of the intended recipient(s) and may contain information that is proprietary, confidential, and exempt from disclosure under applicable law. Any unauthorized review, use, disclosure, or distribution is prohibited. If you have received this email in error please notify the sender by return email and delete the original message. Please note, the recipient should check this email and any attachments for the presence of viruses. The organization accepts no liability for any damage caused by any virus transmitted by this email.
=================================

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html