Feature cropping

classic Classic list List threaded Threaded
5 messages Options
simon walker (BI)-2 simon walker (BI)-2
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Feature cropping

*****
To join, leave or search the confocal microscopy listserv, go to:
http://lists.umn.edu/cgi-bin/wa?A0=confocalmicroscopy
Post images on http://www.imgur.com and include the link in your posting.
*****

Dear List,
This seems like a pretty basic problem, but I can't readily find a solution.  Is it possible in e.g. FIJI/ImageJ to crop around a moving feature to create a movie that will always have the feature of interest at its centre?  What I would ideally like is to specify e.g. 50x50 px ROI, manually position this over the feature of interest, click to select and export the selection to a new file, automatically advance to the next frame and repeat.  Ok, so I could write a script, but surely someone must have done this already??
Thanks,
Simon
mcammer mcammer
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Feature cropping

*****
To join, leave or search the confocal microscopy listserv, go to:
http://lists.umn.edu/cgi-bin/wa?A0=confocalmicroscopy
Post images on http://www.imgur.com and include the link in your posting.
*****

Once you have a method for extracting the feature, put the ROIs in the manager and do something like this.  Years ago we had a macro for aligning based on segmentation on a sperm head followed by a rotation based on he angle of the tail, but it my have been NIH Image & I don;t have time now to look for the macro.




var clipsize = 150;  // edge size of the box for clipping cells for montage
var snipwindow = -1;

//=============================================================================
//  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");    // replace with clear results or just keep adding to results
  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, Optical Microscopy Specialist
http://ocs.med.nyu.edu/microscopy
http://microscopynotes.com/
Cell: (914) 309-3270

________________________________________
From: Confocal Microscopy List [[hidden email]] on behalf of Simon Walker [[hidden email]]
Sent: Monday, July 31, 2017 7:02 AM
To: [hidden email]
Subject: Feature cropping

*****
To join, leave or search the confocal microscopy listserv, go to:
https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.umn.edu_cgi-2Dbin_wa-3FA0-3Dconfocalmicroscopy&d=DQIFaQ&c=j5oPpO0eBH1iio48DtsedbOBGmuw5jHLjgvtN2r4ehE&r=oU_05LztNstAydlbm5L5GDu_vAdjXk3frDLx_CqKkuo&m=KyoK5EQNuzjKSEvww5b1Uaz2T_4Z0-yD-Z65C_VEXAY&s=At0JMVsUH2uS-PEb4ZXaTi4nTj4c8XSoNwlA2zNXanM&e=
Post images on https://urldefense.proofpoint.com/v2/url?u=http-3A__www.imgur.com&d=DQIFaQ&c=j5oPpO0eBH1iio48DtsedbOBGmuw5jHLjgvtN2r4ehE&r=oU_05LztNstAydlbm5L5GDu_vAdjXk3frDLx_CqKkuo&m=KyoK5EQNuzjKSEvww5b1Uaz2T_4Z0-yD-Z65C_VEXAY&s=X3MvhOusE1zT3fIwkUImDzHkixZyFQxYT1mBGu3jpz4&e=  and include the link in your posting.
*****

Dear List,
This seems like a pretty basic problem, but I can't readily find a solution.  Is it possible in e.g. FIJI/ImageJ to crop around a moving feature to create a movie that will always have the feature of interest at its centre?  What I would ideally like is to specify e.g. 50x50 px ROI, manually position this over the feature of interest, click to select and export the selection to a new file, automatically advance to the next frame and repeat.  Ok, so I could write a script, but surely someone must have done this already??
Thanks,
Simon

------------------------------------------------------------
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.
=================================
Klemm, Anna Dr.rer.nat. Klemm, Anna Dr.rer.nat.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Feature cropping

In reply to this post by simon walker (BI)-2
*****
To join, leave or search the confocal microscopy listserv, go to:
http://lists.umn.edu/cgi-bin/wa?A0=confocalmicroscopy
Post images on http://www.imgur.com and include the link in your posting.
*****

Dear Simon,

if you don't need an exact ROI of you object, you could use Plugins >
Tracking > Manual Tracking to get the coordinates of your object over
time quite conveniently. Then run the script below to get rectangular
images following your manually tracked object (the tracking-result
window should be the active window, when running the script).

IJ.renameResults("Results");
windowsize = 50; //size of cropped image in px
title = getTitle();
for (i=0; i<nResults; i++){
slice=getResult("Slice n°", i);
x=getResult("X", i);
y=getResult("Y", i);
run("Specify...", "width="+windowsize+ " height="+windowsize+ " x="+x+"
y="+y+" slice="+slice+" centered");
run("Duplicate...", "title=croppedslice_");
selectWindow(title);
}
run("Images to Stack", "name=Stack title=cropped use");

Kind regards
Anna

On 2017-07-31 13:02, Simon Walker wrote:

> *****
> To join, leave or search the confocal microscopy listserv, go to:
> http://lists.umn.edu/cgi-bin/wa?A0=confocalmicroscopy
> Post images on http://www.imgur.com and include the link in your
> posting.
> *****
>
> Dear List,
> This seems like a pretty basic problem, but I can't readily find a
> solution.  Is it possible in e.g. FIJI/ImageJ to crop around a moving
> feature to create a movie that will always have the feature of
> interest at its centre?  What I would ideally like is to specify e.g.
> 50x50 px ROI, manually position this over the feature of interest,
> click to select and export the selection to a new file, automatically
> advance to the next frame and repeat.  Ok, so I could write a script,
> but surely someone must have done this already??
> Thanks,
> Simon
Sverre Grødem Sverre Grødem
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Feature cropping

In reply to this post by mcammer
*****
To join, leave or search the confocal microscopy listserv, go to:
http://lists.umn.edu/cgi-bin/wa?A0=confocalmicroscopy
Post images on http://www.imgur.com and include the link in your posting.
*****

I would suggest testing the Register Virtual Stack slices [1] plugin,
this should be able to solve the problem headlessly. It is easy to use
and easy to script. If you need it cropped, simply crop the registered
stack and them save as animated gif [2] to make a simple animation. The
plugin features several feature extraction and transformation options,
play with it and see what works.  

Or you could combine the feature extraction with Cammer Michael's clever
macro, although a more precise segmentation might be better suited for
this.

I also recommend you post on the ImageJ forum [3], it is the easiest way
to reach the developers of Fiji and all it's plugins.  

Hope this helps,

Sverre Grødem

Den 2017-07-31 16:15 skreiv Cammer, Michael:

> *****
> To join, leave or search the confocal microscopy listserv, go to:
> http://lists.umn.edu/cgi-bin/wa?A0=confocalmicroscopy
> Post images on http://www.imgur.com and include the link in your posting.
> *****
>
> Once you have a method for extracting the feature, put the ROIs in the
> manager and do something like this.  Years ago we had a macro for
> aligning based on segmentation on a sperm head followed by a rotation
> based on he angle of the tail, but it my have been NIH Image & I don;t
> have time now to look for the macro.
>
> var clipsize = 150;  // edge size of the box for clipping cells for montage
> var snipwindow = -1;
>
> //=============================================================================
> //  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");    // replace with clear results or just keep adding to results
> 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, Optical Microscopy Specialist
> http://ocs.med.nyu.edu/microscopy
> http://microscopynotes.com/
> Cell: (914) 309-3270
>
> ________________________________________
> From: Confocal Microscopy List [[hidden email]] on
> behalf of Simon Walker [[hidden email]]
> Sent: Monday, July 31, 2017 7:02 AM
> To: [hidden email]
> Subject: Feature cropping
>
> *****
> To join, leave or search the confocal microscopy listserv, go to:
> https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.umn.edu_cgi-2Dbin_wa-3FA0-3Dconfocalmicroscopy&d=DQIFaQ&c=j5oPpO0eBH1iio48DtsedbOBGmuw5jHLjgvtN2r4ehE&r=oU_05LztNstAydlbm5L5GDu_vAdjXk3frDLx_CqKkuo&m=KyoK5EQNuzjKSEvww5b1Uaz2T_4Z0-yD-Z65C_VEXAY&s=At0JMVsUH2uS-PEb4ZXaTi4nTj4c8XSoNwlA2zNXanM&e=
> Post images on
> https://urldefense.proofpoint.com/v2/url?u=http-3A__www.imgur.com&d=DQIFaQ&c=j5oPpO0eBH1iio48DtsedbOBGmuw5jHLjgvtN2r4ehE&r=oU_05LztNstAydlbm5L5GDu_vAdjXk3frDLx_CqKkuo&m=KyoK5EQNuzjKSEvww5b1Uaz2T_4Z0-yD-Z65C_VEXAY&s=X3MvhOusE1zT3fIwkUImDzHkixZyFQxYT1mBGu3jpz4&e=
> and include the link in your posting.
> *****
>
> Dear List,
> This seems like a pretty basic problem, but I can't readily find a
> solution.  Is it possible in e.g. FIJI/ImageJ to crop around a moving
> feature to create a movie that will always have the feature of
> interest at its centre?  What I would ideally like is to specify e.g.
> 50x50 px ROI, manually position this over the feature of interest,
> click to select and export the selection to a new file, automatically
> advance to the next frame and repeat.  Ok, so I could write a script,
> but surely someone must have done this already??
> Thanks,
> Simon
>
> ------------------------------------------------------------
> 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.
> =================================
 

Links:
------
[1] https://imagej.net/Register_Virtual_Stack_Slices
[2] http://imagej.net/Save_as_animated_gif
[3] http://forum.imagej.net/
simon walker (BI)-2 simon walker (BI)-2
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Feature cropping

*****
To join, leave or search the confocal microscopy listserv, go to:
http://lists.umn.edu/cgi-bin/wa?A0=confocalmicroscopy
Post images on http://www.imgur.com and include the link in your posting.
*****

Thanks to everyone for their useful suggestions on this.  I'm surprised it's not baked in to ImageJ/FIJI as I would have though it is a relatively common requirement, but clearly that is not the case.
Simon

-----Original Message-----
From: Confocal Microscopy List [mailto:[hidden email]] On Behalf Of Sverre Grødem
Sent: 31 July 2017 18:20
To: [hidden email]
Subject: Re: Feature cropping

*****
To join, leave or search the confocal microscopy listserv, go to:
http://lists.umn.edu/cgi-bin/wa?A0=confocalmicroscopy
Post images on http://www.imgur.com and include the link in your posting.
*****

I would suggest testing the Register Virtual Stack slices [1] plugin, this should be able to solve the problem headlessly. It is easy to use and easy to script. If you need it cropped, simply crop the registered stack and them save as animated gif [2] to make a simple animation. The plugin features several feature extraction and transformation options, play with it and see what works.

Or you could combine the feature extraction with Cammer Michael's clever macro, although a more precise segmentation might be better suited for this.

I also recommend you post on the ImageJ forum [3], it is the easiest way to reach the developers of Fiji and all it's plugins.

Hope this helps,

Sverre Grødem

Den 2017-07-31 16:15 skreiv Cammer, Michael:

> *****
> To join, leave or search the confocal microscopy listserv, go to:
> http://lists.umn.edu/cgi-bin/wa?A0=confocalmicroscopy
> Post images on http://www.imgur.com and include the link in your posting.
> *****
>
> Once you have a method for extracting the feature, put the ROIs in the
> manager and do something like this.  Years ago we had a macro for
> aligning based on segmentation on a sperm head followed by a rotation
> based on he angle of the tail, but it my have been NIH Image & I don;t
> have time now to look for the macro.
>
> var clipsize = 150;  // edge size of the box for clipping cells for
> montage var snipwindow = -1;
>
> //====================================================================
> ========= //  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");    // replace with clear results or just keep adding to results
> 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, Optical Microscopy Specialist
> http://ocs.med.nyu.edu/microscopy http://microscopynotes.com/
> Cell: (914) 309-3270
>
> ________________________________________
> From: Confocal Microscopy List [[hidden email]] on
> behalf of Simon Walker [[hidden email]]
> Sent: Monday, July 31, 2017 7:02 AM
> To: [hidden email]
> Subject: Feature cropping
>
> *****
> To join, leave or search the confocal microscopy listserv, go to:
> https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.umn.edu_cgi-
> 2Dbin_wa-3FA0-3Dconfocalmicroscopy&d=DQIFaQ&c=j5oPpO0eBH1iio48DtsedbOB
> Gmuw5jHLjgvtN2r4ehE&r=oU_05LztNstAydlbm5L5GDu_vAdjXk3frDLx_CqKkuo&m=Ky
> oK5EQNuzjKSEvww5b1Uaz2T_4Z0-yD-Z65C_VEXAY&s=At0JMVsUH2uS-PEb4ZXaTi4nTj
> 4c8XSoNwlA2zNXanM&e=
> Post images on
> https://urldefense.proofpoint.com/v2/url?u=http-3A__www.imgur.com&d=DQ
> IFaQ&c=j5oPpO0eBH1iio48DtsedbOBGmuw5jHLjgvtN2r4ehE&r=oU_05LztNstAydlbm
> 5L5GDu_vAdjXk3frDLx_CqKkuo&m=KyoK5EQNuzjKSEvww5b1Uaz2T_4Z0-yD-Z65C_VEX
> AY&s=X3MvhOusE1zT3fIwkUImDzHkixZyFQxYT1mBGu3jpz4&e=
> and include the link in your posting.
> *****
>
> Dear List,
> This seems like a pretty basic problem, but I can't readily find a
> solution.  Is it possible in e.g. FIJI/ImageJ to crop around a moving
> feature to create a movie that will always have the feature of
> interest at its centre?  What I would ideally like is to specify e.g.
> 50x50 px ROI, manually position this over the feature of interest,
> click to select and export the selection to a new file, automatically
> advance to the next frame and repeat.  Ok, so I could write a script,
> but surely someone must have done this already??
> Thanks,
> Simon
>
> ------------------------------------------------------------
> 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.
> =================================


Links:
------
[1] https://imagej.net/Register_Virtual_Stack_Slices
[2] http://imagej.net/Save_as_animated_gif
[3] http://forum.imagej.net/
The Babraham Institute, Babraham Research Campus, Cambridge CB22 3AT Registered Charity No. 1053902.
The information transmitted in this email is directed only to the addressee. If you received this in error, please contact the sender and delete this email from your system. The contents of this e-mail are the views of the sender and do not necessarily represent the views of the Babraham Institute. Full conditions at: www.babraham.ac.uk<http://www.babraham.ac.uk/terms>
Loading...