source: trunk/projects/misc-plugins/src/main/java/loci/plugins/IntensityMacro_Squirrell_Ogle.ijm @ 7802

Revision 7802, 5.6 KB checked in by fong, 8 years ago (diff)
Line 
1/*
2*       Intensity Macro for ImageJ - customized for Ogle Group
3*       Author: Jimmy Fong (fong@wisc.edu)
4*       Modified by: Jayne Squirrell (jsquirre@wisc.edu)
5*       Purpose:  Performs a background subtraction of intensity
6*               in a ROI selected from a Brightfield image.
7*               Calculates the background-subtracted total
8*               intensity, and intensity per brightfield area.
9*               Also uses a user selected ROI from the Intensity image.
10*               Calculates the background-subtracted total intensity,
11*               and intensity per fluorescent area.
12*               Also saves the fluorescent intensity images after background subtraction over
13*               both the BF area and the FL area.
14*/             
15
16
17//Prompt for Brightfield Image
18Dialog.create("Please Select Brightfield Image");
19Dialog.addMessage("Please Select Brightfield Image");
20Dialog.show();
21
22bfImage = File.openDialog("Brightfield Image");
23open(bfImage);
24bfImageName = getTitle();
25
26Dialog.create("Draw outline of cell/EB");
27Dialog.addMessage("Draw outline of cell/EB");
28Dialog.show();
29
30setTool("freehand");
31
32waitForUser("Use this selection");
33getSelectionCoordinates(xcoords, ycoords);
34getStatistics(bfarea);
35//print(bfarea);
36
37//Open Intensity Image
38run("Open Next");
39intImageName = getTitle();
40
41//Prompt for outline of fluorescent intensity region
42Dialog.create("Draw outline of fluorescent region");
43Dialog.addMessage("Draw outline of fluorescent region");
44Dialog.show();
45
46setTool("freehand");
47
48waitForUser("Use this selection");
49getSelectionCoordinates(xcoordsfl, ycoordsfl);
50getStatistics(flarea);
51//print(flarea);
52
53//deselect fluorescent image outline
54
55run ("Select None");
56
57//Duplicate Fluorescent Image for pre-BG subtract
58run("Duplicate...");
59dupIntImage = getTitle();
60
61
62
63//Prompt for Background Selection
64Dialog.create("Select Background Area");
65Dialog.addNumber("% Background to retain", 10);
66Dialog.show();
67perKept = Dialog.getNumber();
68
69//Make 50 by 50 circle the default bg selection
70setTool("oval");
71makeOval(25,25,50,50);
72getStatistics(bgarea);
73waitForUser("Use this as background");
74
75
76//Calculation of threshold for "background subtraction"
77getHistogram(values, counts, 256);
78//print(values[1]);
79
80
81totalCounts = sumArray(counts);
82countThresh = round(perKept/100 * totalCounts);
83//print("total counts is: " + totalCounts);
84//print("count Thresh is: " + countThresh);
85
86if(countThresh == 0)
87        countThresh =1;
88
89tailCounts = 0;
90firstThrough = 1;
91for (i = counts.length - 1; i != 0; i --){
92        tailCounts += counts[i]; 
93        //print("counts at " + i + "is " + counts[i]);
94        //print("tailCounts is" + tailCounts);
95        if((tailCounts >= countThresh)&& (firstThrough == 1) ){
96                valueThreshold = i;
97                firstThrough = 0;
98        }
99}
100//print("value thresh is" + valueThreshold);
101
102selectWindow(intImageName);
103makeSelection("freehand",xcoords, ycoords);
104run("Subtract...", "value=" + valueThreshold + " slice");
105
106
107getHistogram(NormValues, NormCounts, 256);
108
109//test normvalues
110
111
112
113//print("total norm intensity");
114
115//Calculate the total normalized intensity
116totalNormIntensity =0;
117for(i=0; i<NormValues.length; i++){
118        totalNormIntensity += (NormValues[i] * NormCounts[i]);
119//      print("NormCounts at " + i + "is: " + NormCounts[i]);
120//      print("NormValues at " + i + "is: " + NormValues[i]);
121//      print("totalNormIntensity is: "+ totalNormIntensity);
122//      print("***************************************");
123}
124NormIntperBFArea = totalNormIntensity/bfarea;
125
126selectWindow(dupIntImage);
127makeSelection("freehand",xcoordsfl, ycoordsfl);
128run("Subtract...", "value=" + valueThreshold + " slice");
129
130
131getHistogram(flNormValues, flNormCounts, 256);
132
133//test flnormvalues
134
135
136
137//print("fltotal norm intensity");
138
139//Calculate the fl total normalized intensity
140fltotalNormIntensity =0;
141for(i=0; i<flNormValues.length; i++){
142        fltotalNormIntensity += (flNormValues[i] * flNormCounts[i]);
143//      print("flNormCounts at " + i + "is: " + flNormCounts[i]);
144//      print("flNormValues at " + i + "is: " + flNormValues[i]);
145//      print("fltotalNormIntensity is: "+ fltotalNormIntensity);
146//      print("***************************************");
147}
148
149NormIntperFLArea = fltotalNormIntensity/flarea;
150
151//print("\n"+intImageName +"\nTotal Normalized Intensity is: " + totalNormIntensity + "\nTotal Area(BF) is: " + bfarea + "\n Normalized Intensity per BrightField Area is:" + NormIntperBFArea);
152//print(intImageName);
153
154//print("\n"+intImageName +"\nflTotal Normalized Intensity is: " + fltotalNormIntensity + "\nTotal Area(FL) is: " + flarea + "\n Normalized Intensity per fluorescent Area is:" + NormIntperFLArea);
155//print(intImageName);
156
157selectWindow(intImageName);
158getDimensions(width, height, channels, totalslices, frames);
159actualanalyzedslice = getSliceNumber();
160slicefrombottom = (totalslices - actualanalyzedslice) + 1;
161
162currRow = nResults;
163setResult("Label", currRow, intImageName);
164setResult("Slice from bottom", currRow, slicefrombottom);
165setResult("Background Area", currRow, bgarea);
166setResult("Threshold", currRow, valueThreshold);
167setResult("BF Total Bckgnd Subtracted Int", currRow , totalNormIntensity);
168setResult("Fluor Total Bckgnd Subtracted Int", currRow , fltotalNormIntensity);
169setResult("Brightfield Area(pixels)", currRow, bfarea);
170setResult("Fluorescent Area(pixels)", currRow, flarea);
171setResult("Normalized Int. (Total Bckgnd sub int./BF area", currRow, NormIntperBFArea);
172setResult("Normalized Int. (Total Bckgnd sub int./FL area", currRow, NormIntperFLArea);
173setResult("% Background Retained", currRow, perKept);
174updateResults();
175
176//to save image files with background subtracted
177currentdirectory = File.directory;
178selectWindow(intImageName);
179saveAs("tiff", currentdirectory + "/bgndsub_bfarea_" + intImageName);
180selectWindow(dupIntImage);
181saveAs("tiff", currentdirectory + "/bgndsub_flarea_" + dupIntImage);
182
183
184function sumArray(arr){
185        sum =0;
186        for (i=0;i<arr.length -1; i++){
187                sum += arr[i];
188        }
189        return sum;
190}
191
192
193
194
195
196
197
Note: See TracBrowser for help on using the repository browser.