Skip to content
Snippets Groups Projects
Commit 230493cd authored by lombardo's avatar lombardo
Browse files

first commit: Mykola, a plugin to analyze beads ingestion by c-elegans worm

parents
No related branches found
No related tags found
No related merge requests found
pom.xml 0 → 100644
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>sc.fiji</groupId>
<artifactId>pom-fiji</artifactId>
<version>21.3.0</version>
</parent>
<groupId>BIIS.mpi-cbg</groupId>
<artifactId>Celegans_beads_analysis</artifactId>
<version>1.0.0</version>
<name>Celegans_beads_analysis</name>
<description>
a analysis plugin to measure the quantity of fluorescent Bead ingested by C-Elegans, worm are visualized in transmission
</description>
<dependencies>
<dependency>
<groupId>net.imagej</groupId>
<artifactId>ij</artifactId>
</dependency>
<dependency>
<groupId>sc.fiji</groupId>
<artifactId>fiji-lib</artifactId>
</dependency>
<dependency>
<groupId>sc.fiji</groupId>
<artifactId>Fiji_Plugins</artifactId>
</dependency>
</dependencies>
<developers>
<developer>
<id>developer_id</id>
<name> Benoit </name>
<email>ipf(A_T)mpi-cbg.de</email>
<organization>MPI-CBG</organization>
<roles>
<role>developer</role>
</roles>
<timezone>+1</timezone>
</developer>
</developers>
<repositories>
<!-- NB: for project parent -->
<repository>
<id>imagej.public</id>
<url>http://maven.imagej.net/content/groups/public</url>
</repository>
</repositories>
</project>
package de.mpicbg.scf.cElegansBeadsAnalysis;
import ij.plugin.PlugIn;
import ij.gui.GenericDialog;
import ij.ImagePlus;
import ij.ImageStack;
import ij.process.ImageProcessor;
import ij.IJ;
import ij.CompositeImage;
import ij.plugin.filter.RankFilters;
import ij.plugin.filter.GaussianBlur;
import ij.plugin.ImageCalculator;
import ij.process.ImageStatistics;
/**
* This analysis was designed and implemented by Benoit Lombardot (MPI-CBG Scientific Computing facility)
*
* Description:
*
* Usage:
* - To use the script open it in FIJI editor and run it after opening the image to analyse.
* - Image should have 2 channels, one with a transmission image of the worm and one with an image of the fluorescent bids
* multiple timestep are processed as independent image
* - The user will be requested to input:
* + the channel of the worm
* + the channel of the beads
* + the min area of region to keep in the worm mask
* + the beads threshold type (manual or auto)
* - The plugin will output:
* + an image of the worm mask
* + an image of the bead selection on top of the beads image.
* + 2 lines are appended to the results table indicating respectively the area and mean intensity
* of the worm mask and the area and mean intensity of the beads selection
*
*/
public class Celegans_beads_analysis implements PlugIn {
public int ch_bid, ch_tra, volMin, manual_thresh, R_bid_filt;
public boolean do_manual_thresh, do_bid_filt;
@Override
public void run(String arg) {
if (showDialog()) {
ImagePlus imp_orig = IJ.getImage();
if (imp_orig != null)
process(imp_orig);
}
}
public boolean showDialog(){
GenericDialog gd = new GenericDialog("Process pixels");
gd.addNumericField("transmission channel",2, 0);
gd.addNumericField("bid channel", 1, 0);
gd.addNumericField("minimal mask area", 5000, 0);
gd.addCheckbox("use a manual threshold", false);
gd.addNumericField("manual bid threshold", 200, 0);
gd.showDialog();
if (gd.wasCanceled())
return false;
// get entered values
ch_tra = (int) gd.getNextNumber();
ch_bid = (int) gd.getNextNumber();
volMin = (int) gd.getNextNumber();
do_manual_thresh = gd.getNextBoolean();
manual_thresh = (int) gd.getNextNumber();
return true;
}
public void process(ImagePlus imp_orig){
ImageStack stack = imp_orig.getImageStack();
int Zslice = 1;
for( int frame=1; frame<=imp_orig.getNFrames(); frame++){
//for frame in range(5,6):
// extract the transmission image from the original stack
int stackIdx_tra = imp_orig.getStackIndex(ch_tra,Zslice,frame); // channel, slice, frame
ImageProcessor ip_tra_orig = stack.getProcessor(stackIdx_tra);
ImageProcessor ip_tra = ip_tra_orig.duplicate().convertToFloat();
ImagePlus imp = new ImagePlus("test",ip_tra);
// 1) top hat filtering ( I - open(I) ) of the transmission channel
int radius = 7;
ImageProcessor ip_tra_op = ip_tra.duplicate();
RankFilters filter = new RankFilters();
filter.rank(ip_tra_op, radius, RankFilters.MIN);
filter.rank(ip_tra_op, radius, RankFilters.MAX); // the two successive filter perfom an opening of the image
ImagePlus imp_bg = new ImagePlus("transmission bg", ip_tra_op);
ImageCalculator ImgCalc = new ImageCalculator();
ImagePlus imp_fg = ImgCalc.run("Subtract create", imp, imp_bg);
// 2) gaussian conv of the foreground imp_fg
ImageProcessor ip_fg = imp_fg.getProcessor();
double sigma = 15.0;
GaussianBlur GBlur = new GaussianBlur();
GBlur.blurGaussian(ip_fg, sigma, sigma, 0.02);
// 3) define a threshold and make measure in the worm mask
IJ.setAutoThreshold(imp_fg, "Mean" );
IJ.run(imp_fg, "Convert to Mask", "");
IJ.run(imp_fg, "Invert", "");
IJ.run(imp_fg, "Analyze Particles...", "size="+volMin+"-Infinity show=Masks in_situ");
IJ.setThreshold(imp_fg, 1, 255 ); // set a threshold on the mask before doing the measurement
IJ.run("Set Measurements...","area mean limit redirect=None decimal=3");
IJ.run(imp_fg, "Measure", "");
imp_fg.setTitle("Worms mask");
imp_fg.show();
// extract the bid image for the original image
int stackIdx_bid = imp_orig.getStackIndex(ch_bid,Zslice,frame); // channel, slice, frame;
ImageProcessor ip_bid = stack.getProcessor(stackIdx_bid);
ImagePlus imp_bid = new ImagePlus("bid image", ip_bid.duplicate() );
// filter bid image
ImagePlus imp_bid_fg = imp_bid.duplicate();
// thresold the beads image
ImageStatistics stats = ImageStatistics.getStatistics(imp_bid_fg.getProcessor(), ImageStatistics.MEAN | ImageStatistics.MIN_MAX , imp_bid.getCalibration());
double thresh_bid;
if( do_manual_thresh){ thresh_bid = manual_thresh;}
else{ thresh_bid = 3 * stats.mean; }
IJ.setThreshold(imp_bid_fg,thresh_bid,stats.max);
IJ.run(imp_bid_fg, "Convert to Mask", "");
// create the intersection of beads mask and worm masks
ImagePlus imp_bidMask = ImgCalc.run("AND create", imp_fg, imp_bid_fg);
// create a selection of the mask to make measure on the original bid image
IJ.run(imp_bidMask, "Create Selection", "");
imp_bid = new ImagePlus("bid image", ip_bid.duplicate() );
imp_bid.setRoi(imp_bidMask.getRoi()); // apply the bid selection to the bid image
IJ.run("Set Measurements...","area mean redirect=None decimal=3");
IJ.run(imp_bid, "Measure", "");
// display an image illustrating the results
// original bid and transmission channel + the selection of the
ImageStack stack2 = new ImageStack(imp.getWidth(), imp.getHeight() );
stack2.addSlice( ip_tra_orig );
stack2.addSlice( ip_bid);
ImagePlus imp2 = new ImagePlus("result for frame " + frame , stack2);
imp2.setRoi(imp_bidMask.getRoi());
int nChannels = 2;
int nSlices = 1;
int nFrames = 1;
imp2.setDimensions(nChannels, nSlices, nFrames);
CompositeImage comp = new CompositeImage(imp2, CompositeImage.COMPOSITE);
comp.show();
}
}
public static void main(final String... args)
{
new ij.ImageJ();
IJ.open("F:\\projects\\Mykola_Kurzchalia_paper review_walkin\\data\\Image 1.tif");
Celegans_beads_analysis analyzer = new Celegans_beads_analysis();
analyzer.run("");
}
}
\ No newline at end of file
# Name: Test_plugin
# Author: BL
# Version: 1.0.0
# A single .jar file can contain multiple plugins, specified in separate lines.
#
# The format is: <menu>, "<menu label>", <class name>
#
# If something like ("<arg>") is appended to the class name, the setup() method
# will get that as arg parameter; otherwise arg is simply the empty string.
SCF>Mykola_19xx, "CElegans beads analysis", de.mpicbg.scf.cElegansBeadsAnalysis.Celegans_beads_analysis
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment