forked from CIMA-Imaging-Platform/FIJI_Macros
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIF_NETs.ijm
More file actions
745 lines (585 loc) · 22.9 KB
/
Copy pathIF_NETs.ijm
File metadata and controls
745 lines (585 loc) · 22.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
function macroInfo(){
// * Target User: General
// *
scripttitle= "Netosis Quantification";
version= "1.01";
date= "Sep 2024";
// * Tests Images:
imageAdquisition="2D or Z stack Confocal, Single Channel";
imageType="IF";
voxelSize="Voxel size: unknown um xy";
format="Format: Uncompressed .czi";
//* GUI User Requierments:
//* - Single File and Batch Mode
//*
// Important Parameters: click Im or Dir + right button
parameter1="Apply constrast enhacement if needed ";
// 2 Action tools:
buttom1="Im: Single File processing";
buttom2="DIR: Batch Mode. Select Folder: All images within the folder will be quantified";
// OUTPUT
// Analyzed Images with ROIs
excelName="Quantification_IF_NETs.xls";
feature1="Image Label";
feature2="# Cells";
feature3="# NETs";
feature4="NETs Area [microns^3]";
/*
* version: 1.01
* Author: Tomás Muñoz
* Date : Sep 2024
*
*/
// MIT License
// Copyright (c) 2023 Tomas Muñoz tmsantoro@unav.es
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//image1="../templateImages/cartilage.jpg";
//descriptionActionsTools="
showMessage("ImageJ Script", "<html>"
+"<style>h{margin-top: 5px; margin-bottom: 5px;} p{margin: 0px;padding: 0px;} ol{margin-left: 20px;padding: 5px;} #list-style-3 {list-style-type: circle;.container {max-width: 1200px; margin: 0 auto; padding: 0px; }</style>"
+"<h1><font size=6 color=Teal href=https://cima.cun.es/en/research/technology-platforms/image-platforms>CIMA: Imaging Platform</h1>"
+"<h1><font size=5 color=Purple><i>Software Development Service</i></h1>"
+"<p><font size=2 color=Purple><i>ImageJ Macros</i></p>"
+"<h2><font size=3 color=black>"+scripttitle+"</h2>"
+"<p><font size=2>Modified by Tomas Muñoz Santoro</p>"
+"<p><font size=2>Version: "+version+" ("+date+")</p>"
+"<p><font size=2> contact tmsantoro@unav.es</p>"
+"<p><font size=2> Available for use/modification/sharing under the "+"<p4><a href=https://opensource.org/licenses/MIT/>MIT License</a></p>"
+"<h2><font size=3 color=black>Developed for</h2>"
+"<p><font size=3 i>Input Images</i></p>"
+"<ul id=list-style-3><font size=2 i><li>"+imageAdquisition +"</li><li>"+imageType+"</li><li>"+voxelSize+"</li><li>"+format+"</li></ul>"
+"<p><font size=3 i>Action tools (Buttons)</i></p>"
+"<ol><font size=2 i><li>"+buttom1+"</li></ol>"
+"<p><font size=3 i>PARAMETERS: </i></p>"
+"<ul id=list-style-3><font size=2 i>"
+"<li>"+parameter1+"</li></ul>"
+"<p><font size=3 i>Quantification Results: </i></p>"
+"<p><font size=3 i>AnalyzedImages folder: Visualize Segmented Images</i></p>"
+"<p><font size=3 i>Excel "+excelName+"</i></p>"
+"<ul id=list-style-3><font size=2 i><li>"+feature1+"</li><li>"+feature2+"</li><li>"+feature3+"</li><li>"+feature4+"</li></ul>"
+"<h0><font size=5></h0>"
+"");
//+"<P4><font size=2> For more detailed instructions see "+"<p4><a href=https://www.protocols.io/edit/movie-timepoint-copytoclipboard-tool-chutt6wn>Protocols.io</a><h4> </P4>"
}
var applyContrast=false;
setOption("WaitForCompletion", true);
setOption("ExpandableArrays", true);
macro "NETs Action Tool 1 - Cf00T2d15IT6d10m" {
// Close all open images
close("*");
// Open dialog to select an image file
name = File.openDialog("Select File");
run("Bio-Formats Importer", "open=[" + name + "] autoscale color_mode=Colorized rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT series_1");
// Checks if image is a stack (multiple slices)
getDimensions(width, height, channels, slices, frames);
getVoxelSize(rx, ry, rz, unit);
if (slices > 1) {
run("Subtract Background...", "rolling=50 stack"); // Background subtraction for stacks
run("Z Project...", "projection=[Max Intensity]"); // Z-projection for intensity
}
rename("projection");
selectWindow("projection");
// Display macro information
macroInfo();
// Cell segmentation options:
Dialog.create("Parameters for the analysis");
Dialog.addMessage("NETs segmentation");
Dialog.addCheckbox("Adjust contrast", applyContrast);
Dialog.show();
applyContrast=Dialog.getCheckbox();
// Open ROI Manager
run("ROI Manager...");
// Perform cell counting
NETs("-", "-", name,applyContrast);
}
macro "NETs Action Tool 2 - C00fT0b11DT9b09iTcb09r" {
// Close all open images
close("*");
// Display macro information
macroInfo();
// Open ROI Manager
run("ROI Manager...");
// Prompt user to select a directory
InDir = getDirectory("Choose a Directory");
list = getFileList(InDir);
L = lengthOf(list);
// Cell segmentation options:
Dialog.create("Parameters for the analysis");
Dialog.addMessage("NETs segmentation")
Dialog.addCheckbox("Adjust contrast", applyContrast);
Dialog.show();
applyContrast=Dialog.getCheckbox();
// Disable batch mode
setBatchMode(false);
// Loop through files in the directory and process each one
for (j = 0; j < L; j++) {
if (endsWith(list[j], "czi")) {
name = list[j];
NETs("-", InDir, name,applyContrast);
setBatchMode(false);
}
}
setBatchMode(false);
showMessage("Batch Preprocessing DONE!");
}
function NETs(output, InDir, name,applyContrast) {
/**
* Counts cells in a 2D image stack and performs quantification.
*
* @param output The output directory path.
* @param InDir The input directory path, or "-" if not applicable.
* @param name The name of the image file to process.
*/
// Resets ROI Manager and closes all images
roiManager("reset");
run("Close All");
run("Fresh Start");
// Imports the image using Bio-Formats depending on whether InDir is provided
if (InDir == "-") {
run("Bio-Formats Importer", "open=[" + name + "] autoscale color_mode=Colorized rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT series_1");
} else {
run("Bio-Formats Importer", "open=[" + InDir + name + "] autoscale color_mode=Colorized rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT series_1");
}
setBatchMode(true);
// Retrieves current image title and sets output directory
MyTitle = getTitle();
output = getInfo("image.directory");
OutDir = output + File.separator + "AnalyzedImages";
File.makeDirectory(OutDir); // Creates output directory
aa = split(MyTitle, ".");
MyTitle_short = aa[0]; // Extracts base name from image title
showStatus("Analyzing " + MyTitle);
showStatus("Preprocessing -->"+MyTitle);
print("Preprocessing -->"+MyTitle);
// Checks if image is a stack (multiple slices)
getDimensions(width, height, channels, slices, frames);
getVoxelSize(rx, ry, rz, unit);
if (slices > 1) {
run("Subtract Background...", "rolling=50 stack"); // Background subtraction for stacks
run("Z Project...", "projection=[Max Intensity]"); // Z-projection for intensity
}
rename("projection");
selectWindow("projection");
run("Green");
setBatchMode("show");
close(MyTitle);
// Preprocessing steps: Convert to 8-bit, background subtraction, and contrast enhancement
run("8-bit");
run("Subtract Background...", "rolling=50 stack");
//applyContrast=true;
if (applyContrast){
run("Enhance Local Contrast (CLAHE)", "blocksize=100 histogram=100 maximum=2 mask=*None*");
run("Apply LUT", "stack");
}
/* UNSUPERVISED PIXEL INTENSITY CLASSIFICATION //////////////////////////////////////////////////////////////////////////////////////////////////////////*/
showStatus("Clustering Pixels -->"+MyTitle);
print("Clustering Pixels -->"+MyTitle);
//using k-means clustering (unsupervised method)
run("k-means Clustering ...", "number_of_clusters=4 cluster_center_tolerance=0.01000000 enable_randomization_seed randomization_seed=50");
// Duplicate and convert each cluster into a mask
for (i = 0; i < 4; i++) {
selectWindow("Clusters");
run("Duplicate...", "title=Cluster" + i);
setThreshold(i, i);
setOption("BlackBackground", false);
run("Convert to Mask");
}
// Measures mean intensity of each cluster to classify them
clustersIntensities=newArray();
for (i = 0; i < 4; i++) {
selectWindow("Cluster" + i);
run("Create Selection");
selectWindow("projection");
run("Restore Selection");
meanCluster = getValue("Mean");
clustersIntensities[i]=meanCluster;
print("Cluster"+i+" : "+meanCluster);
run("Select None");
}
// Sort clusters by intensity, from background to nuclei
clusterID = newArray(0, 1, 2, 3);
Array.sort(clustersIntensities, clusterID); // Sort clusters based on intensity
// Assign cluster IDs to relevant categories (background, NETs, nuclei)
bckg = clusterID[0];
NETsLowI = clusterID[1];
NETsHighI = clusterID[2];
nuclei = clusterID[3];
// Rename windows to reflect cluster classification
selectWindow("Cluster" + bckg);
rename("background");
selectWindow("Cluster" + NETsLowI);
rename("NETsLowI");
selectWindow("Cluster" + NETsHighI);
rename("NETsHighI");
selectWindow("Cluster" + nuclei);
rename("nuclei");
close("Clusters");
//waitForUser;
/* CLASSIFY Cells //////////////////////////////////////////////////////////////////////////////////////////////////////////*/
showStatus("Classify Cells -->"+MyTitle);
print("Classify Cells -->"+MyTitle);
// Select nuclei window and clear selection
selectWindow("nuclei");
run("Select None");
// Apply morphological filters for nuclei refinement
run("Morphological Filters", "operation=Closing element=Disk radius=2");
run("Morphological Filters", "operation=Opening element=Disk radius=1");
run("Median","radius=2");
// Analyze particles to identify seeds
run("Analyze Particles...", "size=50-Infinity show=Masks in_situ");
rename("Seeds"); // Rename to 'Seeds'
// Process background for watershed segmentation
selectWindow("background");
run("Select None");
run("Invert");
run("Morphological Filters", "operation=Dilation element=Disk radius=1");
run("Median", "radius=1");
run("Analyze Particles...", "size=50-Infinity show=Masks in_situ");
run("Median","radius=2");
// Duplicate for boundary and edge processing
run("Duplicate...", "title=Boundary");
run("Duplicate...", "title=Edges");
run("Find Edges");
close("*Closing*");
// Perform marker-controlled watershed segmentation
run("Marker-controlled Watershed", "input=Edges marker=Seeds mask=Boundary compactness=0 binary calculate use");
// Threshold to define cell boundaries
run("Threshold...");
getThreshold(lower, upper);
setThreshold(1, upper);
setOption("BlackBackground", false);
wait(10);
run("Convert to Mask");
rename("cells");
run("Clear Results");
// Close temporary windows
close("Seeds");
close("Edges");
close("Boundary");
close("Threshold");
close("background");
run("Clear Results");
roiManager("reset");
//Measure Median Cell Size
selectWindow("cells");
run("Analyze Particles...", "size=1-Infinity circularity=0.6-1.00 show=Nothing display add");
wait(1000);
cellSize = Table.getColumn("Area","Results");
//x = Array.getSequence(lengthOf(aFraction));
//Array.sort(aFraction);
//Array.reverse(aFraction);
//Plot.create("Title", "X-axis Label", "Y-axis Label");
//Plot.addHistogram(aFraction, 1, 0);
Array.getStatistics(cellSize, min, max, mean, stdDev);
bottomSizeFilter=mean-2*stdDev;
topSizeFilter=mean+2*stdDev;
selectWindow("cells");
run("Analyze Particles...", "size="+bottomSizeFilter+"-Infinity circularity=0-1.00 show=Masks in_situ");
nCells=nResults;
print("Cells Detected: "+nCells);
selectWindow("cells");
run("Analyze Particles...", "size="+topSizeFilter+"-Infinity circularity=0-1.00 show=Masks");
rename("topTailCells");
// Array.print(newArray(min, max, mean, stdDev));
// Parametrization (commented out code for future reference)
// This section is intended for histogram creation and statistical analysis
selectWindow("cells");
run("Clear Results");
roiManager("reset");
run("Duplicate...","duplicate");
run("Analyze Particles...", "circularity=0-0.7 show=Masks in_situ");
run("Select None");
rename("possibleNET+");
imageCalculator("OR", "possibleNET+", "topTailCells");
close("topTailCells");
// Prepare NETs from classified cells
selectWindow("background-Dilation");
run("Select All");
setBackgroundColor(255,255,255);
run("Clear");
run("Select None");
rename("NETs");
// Combine low and high intensity NETs
imageCalculator("OR", "NETsLowI", "NETsHighI");
run("Select None");
close("NETsHighI");
// Refine NETsLowI
selectWindow("NETsLowI");
run("Morphological Filters", "operation=Dilation element=Disk radius=1");
run("Morphological Filters", "operation=Erosion element=Disk radius=1");
run("Analyze Particles...", "size=50-Infinite show=Masks in_situ");
//run("Median", "radius=1"); // Apply median filter
/* Identify NETs within possible NET+ based on area percentage //////////////////////////////////////////////////////////////////////////////////////////////////////////*/
run("Clear Results");
roiManager("reset");
// Analyze particles in the "possibleNET+" window
selectWindow("possibleNET+");
run("Morphological Filters", "operation=Erosion element=Disk radius=1");
run("Analyze Particles...", " add");
// Set measurement options to include area and integrated area fraction
run("Set Measurements...", "area shape integrated area_fraction redirect=None decimal=2");
// Process nuclei
selectWindow("nuclei");
run("Select None");
run("Morphological Filters", "operation=Closing element=Disk radius=2");
run("Fill Holes"); // Fill holes in nuclei
run("Median", "radius=1");
// Enlarge the selection from the "nuclei" mask and fill it
setForegroundColor(255, 255, 255);
selectWindow("nuclei-Closing");
run("Create Selection");
selectWindow("NETsLowI-Dilation-Erosion");
run("Restore Selection");
run("Enlarge...", "enlarge=2");
run("Fill");
selectWindow("NETsLowI-Dilation-Erosion");
roiManager("Measure");
//waitForUser;
// Parametrization (commented out code for future reference)
// This section is intended for histogram creation and statistical analysis
/*
aFraction = Table.getColumn("%Area");
x = Array.getSequence(lengthOf(aFraction));
Array.sort(aFraction);
Array.reverse(aFraction);
Plot.create("Title", "X-axis Label", "Y-axis Label");
Plot.addHistogram(aFraction, 1, 0);
Array.getStatistics(aFraction, min, max, mean, stdDev);
Array.print(newArray(min, max, mean, stdDev));
*/
// Filter ROIs based on area and delete those below the threshold
ROIsToDelete = filterTableColum("Results", "%Area", "<", 35);
selectWindow("NETsLowI-Dilation-Erosion");
roiManager("select", ROIsToDelete);
roiManager("delete");
netsDetected=roiManager("count");
print("From NET+ (-->) NETs+ Detected: "+netsDetected);
if(netsDetected>0){
selectWindow("NETsLowI");
run("Duplicate...","title=NETsDetected ignore");
run("Select None");
roiManager("combine");
run("Clear Outside");
imageCalculator("OR", "NETs", "NETsDetected");
close("NETsDetected");
}
selectWindow("NETs");
//waitForUser;
// Detect Isolated NETs
selectWindow("cells");
run("Morphological Filters", "operation=Closing element=Disk radius=2");
run("Create Selection");
selectWindow("NETsLowI");
run("Restore Selection");
run("Enlarge...","enlarge=3");
run("Clear");
run("Select None");
selectWindow("nuclei");
run("Invert");
run("Fill Holes");
run("Invert");
run("Create Selection");
selectWindow("NETsLowI");
run("Restore Selection");
run("Enlarge...","enlarge=5");
run("Clear");
run("Morphological Filters", "operation=Closing element=Disk radius=2");
run("Median","radius=1");
run("Select All");
run("Enlarge...","enlarge=-5");
run("Clear Outside");
run("Select None");
run("Analyze Particles...", "size=300-Infinity circularity=0-0.5 show=Masks in_situ exclude");
rename("NETsIsolated");
imageCalculator("OR", "NETs","NETsIsolated");
selectWindow("NETs");
run("Morphological Filters", "operation=Closing element=Disk radius=2");
rename("ROIs");
setBatchMode("show");
close("NETs*");
close("nuclei*");
close("cells*");
close("possible*");
setBatchMode("exit and display");
// SEMIAUTOMATIC -- USER EDITION -- just in single file processing
if (InDir == "-") {
deleteROIsFun("ROIs", "projection");
addROIsFun("ROIs", "projection");
}
run("Clear Results");
roiManager("reset");
selectWindow("ROIs");
run("Analyze Particles...", "show=Nothing display add");
netsDetected=roiManager("count");
print("From NET+ (-->) NETs+ Detected: "+netsDetected);
selectWindow("ROIs");
run("Create Selection");
areaNets=getValue("Area");
areaNets=areaNets*rx*ry;
//print(areaNets);
//waitForUser;
run("Clear Results");
roiManager("reset");
selectWindow("ROIs");
run("Create Selection");
selectWindow("projection");
run("Green");
run("Restore Selection");
run("Flatten");
saveAs("Tiff", OutDir + File.separator + MyTitle_short+"Analyzed");
//--Save results
run("Clear Results");
if(File.exists(output+File.separator+"QuantificationResults_IF_NETs.xls"))
{
//if exists add and modify
open(output+File.separator+"QuantificationResults_IF_NETs.xls");
IJ.renameResults("Results");
}
i=nResults;
setResult("[Label]", i, MyTitle);
setResult("#Cells",i,nCells);
setResult("# NETs ",i,netsDetected);
setResult("NETsArea(um2)",i,areaNets);
saveAs("Results", output+File.separator+"QuantificationResults_IF_NETs.xls");
close("projection");
}
function filterTableColum(tableName, columnName, filterType, threshold)
{
/**
* Filters a table column based on a given threshold.
*
* @param {string} tableName - The name of the table window.
* @param {string} columnName - The name of the column to filter.
* @param {string} filterType - The type of filtering ("<" for values less than, ">" for values
* @param {number} threshold - The threshold value for filtering.
* @return {array} positiveRois - An array containing the indices of rows that meet the filterin
*/
//TEST PARAMETERS
/*
tableName="Results";
columnName="Mean";
filterType=">";
threshold=0;*/
// Select the table window
selectWindow(tableName);
// Get the number of results in the table
n = nResults;
// Create an array of indices for the table rows
id = Array.slice(Array.getSequence(n + 1), 0, n);
// Set the "Index" column in the table
Table.setColumn("Index", id);
// Sort the table based on the specified column
Table.sort(columnName);
// Get the specified column from the table
column = Table.getColumn(columnName);
// Loop through the values in the column
for (i = 0; i < lengthOf(column); i++) {
// Get the value at the current position
value = column[i];
// Check if the filter type is "<"
if (filterType == "<") {
// If the value is greater than the threshold, delete rows below the current position
if (value > threshold) {
selectWindow(tableName);
Table.deleteRows(i, lengthOf(column) - 1);
break;
}
} else if (filterType == ">") {
// If the value is greater than the threshold, delete rows above the current position
if (value > threshold) {
selectWindow(tableName);
Table.deleteRows(0, i - 1);
break;
}
}
}
// Get the updated indices of rows that meet the filtering criteria
positiveRois = Table.getColumn("Index");
// Return the array of positive indices
return positiveRois;
}
function deleteROIsFun(Mask, orig) {
selectWindow(Mask);
run("Create Selection");
type=selectionType();
if (type !=-1){
selectWindow(orig);
run("Restore Selection");
// Loop to delete multiple ROIs if desired
deleteROIs = getBoolean("Do you want to Delete Detected NETs");
while (deleteROIs) {
// Prompt the user to draw a ROI to delete
setTool("freehand");
waitForUser("Please Draw ROI to delete and press OK when ready");
// Check if a selection is made
type = selectionType();
if (type == -1) {
showMessage("Edition", "You should DRAW a REGION. Otherwise nothing will be deleted.");
}else{
// Apply the selection to the mask image
selectWindow(Mask);
setBatchMode("show");
run("Restore Selection");
setForegroundColor(255, 255, 255);
run("Fill", "slice");
run("Create Selection");
// Apply the selection to the original image
selectWindow(orig);
run("Restore Selection");
// Prompt the user to delete another ROI
selectWindow(orig);
deleteROIs = getBoolean("Do you want to Delete other Detected Regions");
}
}
}
}
function addROIsFun(Mask, orig) {
selectWindow(Mask);
run("Create Selection");
type=selectionType();
if (type !=-1){
selectWindow(orig);
run("Restore Selection");
// Loop to add multiple ROIs if desired
addROIs = getBoolean("Do you want to ADD NETs");
while (addROIs) {
// Prompt the user to draw a ROI to delete
setTool("freehand");
selectWindow(orig);
waitForUser("Please Draw Vessels ROI and press OK when ready");
// Check if a selection is made
type = selectionType();
if (type == -1) {
showMessage("Edition", "You should DRAW a REGION. Otherwise nothing will be added.");
exit();
}
// Apply the selection to the mask image
selectWindow(Mask);
setBatchMode("show");
run("Restore Selection");
setForegroundColor(0, 0, 0);
run("Fill", "slice");
run("Create Selection");
// Apply the selection to the original image
selectWindow(orig);
run("Restore Selection");
// Prompt the user to add another ROI
selectWindow(orig);
addROIs = getBoolean("Do you want to add other Detected Regions");
}
}
}