Skip to content

Commit

Permalink
Added series-selection annotation
Browse files Browse the repository at this point in the history
Image IDs can now be annotated with '@' symbols to select a specific
series index. The syntax is:

* <ID>@<series#>@<.ext>

For example: test@27@.jpeg would open the 27th series of test.jpeg

The @<series#>@ can appear anywhere in the id, but if it appears in the
extension the image will probably not be supported correctly.

So te@27@st.jpeg is ok and would also open the 27th series of test.jpeg,
but test.jp@27@eg is not supported.
  • Loading branch information
hinerm committed Jul 2, 2013
1 parent 56224a9 commit 3661b29
Showing 1 changed file with 40 additions and 8 deletions.
48 changes: 40 additions & 8 deletions src/main/java/loci/scifio/itk/SCIFIOITKBridge.java
Expand Up @@ -123,9 +123,24 @@ public boolean executeCommand(String commandLine) throws IOException
private boolean executeCommand(String [] args) throws IOException {
boolean success = false;


String series = "0";
String id = "";
String[] idTokens = null;

if (args.length > 1) {
idTokens = args[1].split("@");
id = idTokens[0];

if (idTokens.length == 3) {
id += idTokens[2];
series = idTokens[1];
}
}

try {
if(args[0].equals("info")) {
success = readImageInfo(args[1]);
success = readImageInfo(id, series);
endCommand();
}
else if(args[0].equals("read")) {
Expand All @@ -139,15 +154,15 @@ else if(args[0].equals("read")) {
int tEnd = Integer.parseInt( args[9] ) + tBegin - 1;
int cBegin = Integer.parseInt( args[10] );
int cEnd = Integer.parseInt( args[11] ) + cBegin - 1;
success = read(args[1], xBegin, xEnd, yBegin, yEnd, zBegin, zEnd, tBegin,
success = read(id, series, xBegin, xEnd, yBegin, yEnd, zBegin, zEnd, tBegin,
tEnd, cBegin, cEnd);
}
else if(args[0].equals("canRead")) {
success = canRead(args[1]);
success = canRead(id);
endCommand();
}
else if(args[0].equals("canWrite")) {
success = canWrite(args[1]);
success = canWrite(id);
endCommand();
}
else if(args[0].equals("waitForInput")) {
Expand Down Expand Up @@ -184,7 +199,7 @@ else if(args[0].equals("write")) {
if(useCM == 1)
cm = buildColorModel(args, byteOrder);

success = write(args[1], cm, byteOrder, dims, dimx, dimy, dimz, dimt,
success = write(id, series, cm, byteOrder, dims, dimx, dimy, dimz, dimt,
dimc, pSizeX, pSizeY, pSizeZ, pSizeT, pSizeC, pixelType, rgbCCount,
xStart, yStart, zStart, tStart, cStart, xCount, yCount, zCount, tCount,
cCount);
Expand All @@ -211,11 +226,14 @@ else if(args[0].equals("write")) {
* initialized reader (beginning with "hash:") as given by a call to "info"
* earlier.
*/
public boolean readImageInfo(String filePath)
public boolean readImageInfo(String filePath, String series)
throws FormatException, IOException
{
createReader(filePath);

int oldSeries = reader.getSeries();
if (!series.equalsIgnoreCase("all")) reader.setSeries(Integer.parseInt(series));

final MetadataStore store = reader.getMetadataStore();
IMetadata meta = (IMetadata) store;

Expand Down Expand Up @@ -310,6 +328,8 @@ public boolean readImageInfo(String filePath)

System.err.println("I am done reading image information in java");

reader.setSeries(oldSeries);

return true;
}

Expand All @@ -323,7 +343,7 @@ public boolean readImageInfo(String filePath)
* second time with a fresh reader object. Regardless, after reading the
* file, the reader closes the file handle, and invalidates its hash token.
*/
public boolean read(String filePath,
public boolean read(String filePath, String series,
int xBegin, int xEnd,
int yBegin, int yEnd,
int zBegin, int zEnd,
Expand All @@ -333,6 +353,9 @@ public boolean read(String filePath,
{
createReader(filePath);

int oldSeries = reader.getSeries();
if (!series.equalsIgnoreCase("all")) reader.setSeries(Integer.parseInt(series));

int rgbChannelCount = reader.getRGBChannelCount();
int bpp = FormatTools.getBytesPerPixel( reader.getPixelType() );
int xCount = reader.getSizeX();
Expand Down Expand Up @@ -385,13 +408,16 @@ public boolean read(String filePath,
}
}
out.flush();

reader.setSeries(oldSeries);

return true;
}

/**
*
*/
public boolean write ( String fileName, ColorModel cm, int byteOrder, int dims,
public boolean write ( String fileName, String series, ColorModel cm, int byteOrder, int dims,
int dimx, int dimy, int dimz, int dimt, int dimc, double pSizeX,
double pSizeY, double pSizeZ, double pSizeT, double pSizeC,
int pixelType, int rgbCCount, int xStart, int yStart,
Expand All @@ -404,6 +430,9 @@ public boolean write ( String fileName, ColorModel cm, int byteOrder, int dims,
meta.setPixelsID("Pixels:0", 0);
meta.setPixelsDimensionOrder(DimensionOrder.XYZTC, 0);

int oldSeries = reader.getSeries();
if (!series.equalsIgnoreCase("all")) reader.setSeries(Integer.parseInt(series));

try {
meta.setPixelsType(PixelType.fromString(FormatTools.getPixelTypeString(pixelType)), 0);

Expand Down Expand Up @@ -489,6 +518,9 @@ public boolean write ( String fileName, ColorModel cm, int byteOrder, int dims,
writer.close();

printAndFlush(System.out, "Done writing image: " + fileName + "\n");

reader.setSeries(oldSeries);

return true;
}

Expand Down

0 comments on commit 3661b29

Please sign in to comment.