Skip to content

Commit

Permalink
Add option to duplicate missing planes in a Z stack
Browse files Browse the repository at this point in the history
  • Loading branch information
melissalinkert committed Feb 25, 2025
1 parent 743d1e8 commit c9b7c30
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions components/formats-gpl/src/loci/formats/in/InCellReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ public class InCellReader extends FormatReader {

// -- Constants --

public static final String DUPLICATE_PLANES_KEY = "incell.duplicate_missing_planes";
public static final boolean DUPLICATE_PLANES_DEFAULT = true;

public static final String INCELL_MAGIC_STRING = "IN Cell Analyzer";
public static final String CYTELL_MAGIC_STRING = "Cytell";

Expand Down Expand Up @@ -127,6 +130,17 @@ public InCellReader() {
".im file";
}

// -- InCellReader API methods --

public boolean duplicatePlanes() {
MetadataOptions options = getMetadataOptions();
if (options instanceof DynamicMetadataOptions) {
return ((DynamicMetadataOptions) options).getBoolean(
DUPLICATE_PLANES_KEY, DUPLICATE_PLANES_DEFAULT);
}
return DUPLICATE_PLANES_DEFAULT;
}

// -- IFormatReader API methods --

/* @see loci.formats.IFormatReader#isThisType(String, boolean) */
Expand Down Expand Up @@ -191,9 +205,18 @@ public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h)
getSeries() % channelsPerTimepoint.size() : coordinates[2];
int image = getIndex(coordinates[0], coordinates[1], 0);

if (imageFiles[well][field][timepoint][image] == null) return buf;
if (imageFiles[well][field][timepoint][image] == null) {
// unless otherwise configured, copy the first Z section
// to any other planes in the Z stack that are missing
if (duplicatePlanes() && coordinates[0] > 0) {
return openBytes(getIndex(0, coordinates[1], coordinates[2]), buf, x, y, w, h);
}
return buf;
}
String filename = imageFiles[well][field][timepoint][image].filename;
if (filename == null || !(new Location(filename).exists())) return buf;
if (filename == null || !(new Location(filename).exists())) {
return buf;
}

if (imageFiles[well][field][timepoint][image].isTiff) {
try {
Expand Down Expand Up @@ -330,6 +353,14 @@ public int getOptimalTileHeight() {

// -- Internal FormatReader API methods --

/* @see loci.formats.FormatReader#getAvailableOptions() */
@Override
protected ArrayList<String> getAvailableOptions() {
ArrayList<String> optionsList = super.getAvailableOptions();
optionsList.add(DUPLICATE_PLANES_KEY);
return optionsList;
}

/* @see loci.formats.FormatReader#initFile(String) */
@Override
protected void initFile(String id) throws FormatException, IOException {
Expand Down

0 comments on commit c9b7c30

Please sign in to comment.