Skip to content

Commit

Permalink
Threshold options for reformat sections and minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
lahammond committed Feb 9, 2023
1 parent 9d97d0d commit 84db4df
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 48 deletions.
Binary file added BrainJ-1.0.7.jar
Binary file not shown.
File renamed without changes.
Binary file added Previous Releases/BrainJ-1.0.6.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</parent>

<groupId>com.zuckerman.cellularimaging</groupId>
<version>1.0.5</version>
<version>1.0.7</version>

<name>BrainJ</name>
<url>https://zuckermaninstitute.columbia.edu</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
//Image coordinates can be extracted from Nikon ND2 files for automated reordering of sections, otherwise alphanumeric filenames can be used. <br> <br> "


BrainJVer ="BrainJ 1.0.5";
ReleaseDate= "January 6, 2021";
BrainJVer ="BrainJ 1.0.7";
ReleaseDate= "February 9, 2023";

// Initialization
requires("1.52p");
Expand All @@ -48,6 +48,8 @@ run("Close All");
// Select input directories

#@ File[] listOfPaths(label="select files or folders", style="both")
#@ String(label="Threshold method for section detection:", choices={"Otsu", "Li", "Mean"}, style="radioButtonHorizontal", description="Otsu generally works well, try alternatives if areas missing from sections.") ThreshMethod

//#@ boolean(label="Use GPU-acceleration (requires CLIJ)?", value = false, description="") GPU_ON

GPU_ON = false
Expand Down Expand Up @@ -237,7 +239,7 @@ for (FolderNum=0; FolderNum<listOfPaths.length; FolderNum++) {
function ReformatSeries(input, FinalRes) {
//run by : ReformatSeries(input, FinalRes);

run("Collect Garbage");
collectGarbage(10, 4);

files = getFileList(input);
files = ImageFilesOnlyArray(files);
Expand Down Expand Up @@ -285,7 +287,7 @@ function ReformatSeries(input, FinalRes) {
File.mkdir(input + "1_Reformatted_Sections/"+j);
}

run("Collect Garbage");
collectGarbage(10, 4);

if(FinalRes > 0) {
Rescale = InputRes/FinalRes;
Expand Down Expand Up @@ -413,7 +415,7 @@ function ReformatSeries(input, FinalRes) {
//Automatic Detection settings
run("Subtract Background...", "rolling=25");
//setThreshold(45, 65535);
run("Auto Threshold", "method=Mean white");
run("Auto Threshold", "method="+ThreshMethod+" white");
setOption("BlackBackground", true);
run("Convert to Mask");
run("Median...", "radius=2");
Expand All @@ -432,7 +434,8 @@ function ReformatSeries(input, FinalRes) {
run("Subtract...", "value="+BGround+"");
// Apply Threshold
run("Set Measurements...", "mean fit redirect=None decimal=3");
run("Auto Threshold", "method=Mean white");

run("Auto Threshold", "method="+ThreshMethod+" white");
setOption("BlackBackground", true);
run("Colors...", "foreground=white background=black selection=yellow");
run("Convert to Mask");
Expand Down Expand Up @@ -571,7 +574,7 @@ function ReformatSeries(input, FinalRes) {
close();
}
}
run("Collect Garbage");
collectGarbage(10, 4);

if (i == 0) {
Sectionend = getTime();
Expand Down Expand Up @@ -652,7 +655,7 @@ function CreateSectionPreview(InputFolder, FinalRes) {
run("Time Stamper", "starting=1 interval=1 x=5 y=16 font=14 decimal=0 anti-aliased or= ");
saveAs("Tiff", input + "2_Section_Preview/Section_Preview_Stack.tif");
close();
run("Collect Garbage");
collectGarbage(10, 4);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Export = input + "1_Reformatted_Sections/";
ChNum = CountSubFolders(Export);
ChArray = NumberedArray(ChNum);

run("Collect Garbage");
collectGarbage(10, 4);

// Process each channel
for(j=1; j<ChNum+1; j++) {
Expand All @@ -89,6 +89,7 @@ for(j=1; j<ChNum+1; j++) {
//run("Save");
saveAs("Tiff", FileFolder + image);
close();
collectGarbage(10, 4);
}
//Vertically
for(i=0; i<VFlipIdx.length; i++) {
Expand All @@ -104,6 +105,7 @@ for(j=1; j<ChNum+1; j++) {
//run("Save");
saveAs("Tiff", FileFolder + image);
close();
collectGarbage(10, 4);
}
//Replacing
for(i=0; i<ReplaceIdx.length; i++) {
Expand All @@ -127,9 +129,10 @@ for(j=1; j<ChNum+1; j++) {
run("Select None");
saveAs("Tiff", FileFolder + image);
close();
collectGarbage(10, 4);
}
}
run("Collect Garbage");
collectGarbage(10, 4);
print("");
}

Expand All @@ -144,7 +147,7 @@ File.mkdir(input + "2_Section_Preview");

print("Creating scaled down stack for checking section quality and order..");
//setBatchMode(false);
run("Collect Garbage");
collectGarbage(10, 4);

if (ChNum > 1) {
for(j=1; j<ChArray.length+1; j++) {
Expand Down Expand Up @@ -215,7 +218,7 @@ run("Time Stamper", "starting=1 interval=1 x=1 y=16 font=14 decimal=0 anti-alias
saveAs("Tiff", input + "2_Section_Preview/Section_Preview_Stack.tif");
close();

run("Collect Garbage");
collectGarbage(10, 4);



Expand Down Expand Up @@ -293,3 +296,13 @@ function LocateValue(inputArray, VarName) {
return Value;
}

function collectGarbage(slices, itr){
setBatchMode(false);
wait(1000);
for(i=0; i<itr; i++){
wait(50*slices);
run("Collect Garbage");
call("java.lang.System.gc");
}
setBatchMode(true);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ run("Colors...", "foreground=white background=black selection=yellow");
run("Clear Results");
run("Close All");

BrainJVer ="BrainJ 1.0.5";
ReleaseDate= "January 6, 2021";
BrainJVer ="BrainJ 1.0.7";
ReleaseDate= "February 9, 2023";


#@ File[] listOfPaths(label="Select experiment/brain folders:", style="both")
Expand Down Expand Up @@ -1296,8 +1296,8 @@ if (CellPlotCheck > 0) {

if (CellAnalysisON == true) {
print("");
print("Bregma coordinates have been provided by comparing multiple landmarks to determine the following linear transformations:");
print(" Bregma_AP = (ZPosition*25-5350)*-1 Bregma_DV = (YPosition*25-470)*-1 Bregma_ML = XPosition*25-5700");
//print("Bregma coordinates have been provided by comparing multiple landmarks to determine the following linear transformations:");
//print(" Bregma_AP = (ZPosition*25-5350)*-1 Bregma_DV = (YPosition*25-470)*-1 Bregma_ML = XPosition*25-5700");
}

selectWindow("Log");
Expand Down Expand Up @@ -3155,7 +3155,7 @@ function AnnotatePoints (PointsIn, AtlasAnnotationImg, AtlasAnnotationCSV, Measu
OutputRegionIDs[i] = getResult("output_id", i);
}
RegionNames[i] = getResultString("name", i);
RegionAcr[i] = getResultString("acronym", i);
RegionAcr[i] = "\"" + getResultString("acronym", i)+ "\"";
ParentIDs[i] = getResultString("parent_ID", i);
ParentNames[i] = getResultString("parent_acronym", i);
Graph_Order[i] = getResultString("graph_order", i);
Expand All @@ -3174,7 +3174,8 @@ function AnnotatePoints (PointsIn, AtlasAnnotationImg, AtlasAnnotationCSV, Measu
// 2) Open file to write into
WriteOut = File.open(CellFileOut);
// 3) Print headings
print(WriteOut, "X,Y,Z,Z_Dither,Bregma_AP,Bregma_DV,Bregma_ML,Mean_Int_Ch1,Mean_Int_Ch2,Mean_Int_Ch3,Mean_Int_Ch4,Hemisphere,ID,Acronym\n");
print(WriteOut, "X,Y,Z,Z_Dither,Mean_Int_Ch1,Mean_Int_Ch2,Mean_Int_Ch3,Mean_Int_Ch4,Hemisphere,ID,Acronym\n");
//print(WriteOut, "X,Y,Z,Z_Dither,Bregma_AP,Bregma_DV,Bregma_ML,Mean_Int_Ch1,Mean_Int_Ch2,Mean_Int_Ch3,Mean_Int_Ch4,Hemisphere,ID,Acronym\n");
//print(WriteOut, "X,Y,Z,Z_Dither,Mean_Int_Ch1,Mean_Int_Ch2,Mean_Int_Ch3,Mean_Int_Ch4,Hemisphere,ID\n");


Expand All @@ -3186,9 +3187,9 @@ function AnnotatePoints (PointsIn, AtlasAnnotationImg, AtlasAnnotationCSV, Measu
} else {
HemisphereArray[i] = "Left";
}
BregmaAP = ((ZPos[i]*25)-5350)*-1;
BregmaDV = ((YPos[i]*25)-470)*-1;
BregmaML = XPos[i]*25-5700;
//BregmaAP = ((ZPos[i]*25)-5350)*-1;
//BregmaDV = ((YPos[i]*25)-470)*-1;
//BregmaML = XPos[i]*25-5700;

// Update Region Intensity to Reflect OutputIDs
location = LocateID(RegionIDs, MeanMeasurements[i]);
Expand All @@ -3198,8 +3199,8 @@ function AnnotatePoints (PointsIn, AtlasAnnotationImg, AtlasAnnotationCSV, Measu


//print(WriteOut, XPos[i]+","+YPos[i]+","+ZPos[i]+","+Z_Dither[i]+","+BregmaAP+","+BregmaDV+","+BregmaML+","+MeanIntCh1[i]+","+MeanIntCh2[i]+","+MeanIntCh3[i]+","+MeanIntCh4[i]+","+HemisphereArray[i]+","+MeanMeasurements[i]);

print(WriteOut, XPos[i]+","+YPos[i]+","+ZPos[i]+","+Z_Dither[i]+","+BregmaAP+","+BregmaDV+","+BregmaML+","+MeanIntCh1[i]+","+MeanIntCh2[i]+","+MeanIntCh3[i]+","+MeanIntCh4[i]+","+HemisphereArray[i]+","+trueID+","+trueAcr);
//print(WriteOut, XPos[i]+","+YPos[i]+","+ZPos[i]+","+Z_Dither[i]+","+BregmaAP+","+BregmaDV+","+BregmaML+","+MeanIntCh1[i]+","+MeanIntCh2[i]+","+MeanIntCh3[i]+","+MeanIntCh4[i]+","+HemisphereArray[i]+","+trueID+","+trueAcr);
print(WriteOut, XPos[i]+","+YPos[i]+","+ZPos[i]+","+Z_Dither[i]+","+MeanIntCh1[i]+","+MeanIntCh2[i]+","+MeanIntCh3[i]+","+MeanIntCh4[i]+","+HemisphereArray[i]+","+trueID+","+trueAcr);
}

// 5) Close file
Expand Down Expand Up @@ -3459,7 +3460,7 @@ function MeasureIntensitiesLRHemisphereFullRes(Channel) {
OutputRegionIDs[i] = getResult("output_id", i);
}
RegionNames[i] = getResultString("name", i);
RegionAcr[i] = getResultString("acronym", i);
RegionAcr[i] = "\"" + getResultString("acronym", i)+ "\"";
ParentIDs[i] = getResultString("parent_ID", i);
ParentNames[i] = getResultString("parent_acronym", i);
Graph_Order[i] = getResultString("graph_order", i);
Expand Down Expand Up @@ -5375,7 +5376,7 @@ function CreateDensityTableLRHemisphereFullRes(Channel, ProBGround) {
OutputRegionIDs[i] = getResult("output_id", i);
}
RegionNames[i] = getResultString("name", i);
RegionAcr[i] = getResultString("acronym", i);
RegionAcr[i] = "\"" + getResultString("acronym", i)+ "\"";
ParentIDs[i] = getResultString("parent_ID", i);
ParentNames[i] = getResultString("parent_acronym", i);
Graph_Order[i] = getResultString("graph_order", i);
Expand Down Expand Up @@ -6239,8 +6240,8 @@ function CreateCellDensityTableLRHemisphereFullResSpinalCord(Channel) {

for(i=0; i<NumIDs; i++) {
RegionIDs[i] = getResult("id", i);
RegionNames[i] = getResultString("name", i);
RegionAcronyms[i] = getResultString("acronym", i);
RegionNames[i] = "\"" + getResultString("name", i)+ "\"";
RegionAcronyms[i] = "\"" + getResultString("acronym", i)+ "\"";
ParentIDs[i] = getResult("parent_ID", i);
ParentAcronyms[i] = "\"" + getResultString("parent_acronym", i) + "\"";
ChildAcronyms[i] = "\"" + getResultString("children_acronym", i) +"\"";
Expand Down Expand Up @@ -6391,8 +6392,8 @@ function SCCreateSummaryRows (InputTable) {

for(i=0; i<NumIDs; i++) {
RegionIDs[i] = getResult("id", i);
RegionNames[i] = getResultString("name", i);
RegionAcronyms[i] = getResultString("acronym", i);
RegionNames[i] = "\"" + getResultString("name", i) + "\"";
RegionAcronyms[i] = "\"" + getResultString("acronym", i) + "\"";
ParentIDs[i] = getResult("parent_ID", i);
ParentAcronyms[i] = "\"" + getResultString("parent_acronym", i) + "\"";
ChildAcronyms[i] = "\"" + getResultString("children_acronym", i) +"\"";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,18 @@ function RenameSectionFilesFromND2Coord(input) {
for(filen=0; filen<files.length; filen++) {
image = files[filen];

run("Bio-Formats Importer", "open=[" + input + image + "] color_mode=Default display_metadata rois_import=[ROI manager] view=[Metadata only] stack_order=Default");
selectWindow("Original Metadata - " + image );
saveAs( "Results", input + "temp_metadata.txt" );
selectWindow("Original Metadata - " + image );
run("Close");

run("Bio-Formats Macro Extensions");
Ext.setId(input + image);
Ext.getMetadataValue("dXPos", XPos);
Ext.getMetadataValue("dYPos", YPos);


//run("Bio-Formats Importer", "open=[" + input + image + "] color_mode=Default display_metadata rois_import=[ROI manager] view=[Metadata only] stack_order=Default");
//selectWindow("Original Metadata - " + image );
//saveAs( "Results", input + "temp_metadata.txt" );
//selectWindow("Original Metadata - " + image );
//run("Close");

// Process name

Expand All @@ -74,28 +81,26 @@ function RenameSectionFilesFromND2Coord(input) {
slide511=100+parseInt(substring(image,7,9));
}
smTitle = "Slide"+slide511+"_";


}


//Get Metadata from Image

Metadata = split( File.openAsString( input + "temp_metadata.txt" ), "\n" );
//Metadata = split( File.openAsString( input + "temp_metadata.txt" ), "\n" );



for(i=0; i<Metadata.length; i++){
if(matches(Metadata[i],".*dXPos.*") == 1){
XRow=i;
}
if(matches(Metadata[i],".*dYPos.*") == 1){
YRow=i;
}
}
//for(i=0; i<Metadata.length; i++){
//if(matches(Metadata[i],".*dXPos.*") == 1){
//XRow=i;
//}
//if(matches(Metadata[i],".*dYPos.*") == 1){
//YRow=i;
//}
//}

XPos=substring(Metadata[XRow],8,10);
YPos=substring(Metadata[YRow],8,10);
//XPos=substring(Metadata[XRow],8,10);
//YPos=substring(Metadata[YRow],8,10);

if (SectionArrangement == "Right and Down"){
if (YPos >=30) {
Expand Down

0 comments on commit 84db4df

Please sign in to comment.