Skip to content
This repository has been archived by the owner on Mar 17, 2023. It is now read-only.

Commit

Permalink
* ROIIntensityDescriptor: changed IntensityDescriptorInfos field to
Browse files Browse the repository at this point in the history
public otherwise we just can't use the static compute method.
* MetadataUtil: added cleanTiffData(), cleanBinData() and cleanPlanes()
methods.
* ROIDescriptor: added getDescriptors() and computeDescriptor(..)
methods.
* remove POI library from Icy-Kernel package.
* version change
  • Loading branch information
Stephane-D committed Jul 26, 2016
1 parent 3c05aea commit ffa46c2
Show file tree
Hide file tree
Showing 6 changed files with 217 additions and 50 deletions.
3 changes: 1 addition & 2 deletions META-INF/MANIFEST.MF
Expand Up @@ -10,8 +10,7 @@ Class-Path: resources.jar ij/ij.jar lib/arpack-combo.jar lib/bioformats.jar
lib/jfreechart.jar lib/jmf.jar lib/joal.jar lib/jocl.jar lib/jogl-all.jar
lib/jplasma.jar lib/jtransforms.jar lib/junit.jar lib/jxl.jar
lib/laf-plugin.jar lib/laf-widget.jar lib/mediaplayer.jar lib/multiplayer.jar
lib/netlib-java.jar lib/optimization.jar lib/parallelcolt.jar lib/poi.jar
lib/poi-excelant.jar lib/poi-ooxml.jar lib/poi-ooxml-schemas.jar lib/poi-scratchpad.jar
lib/netlib-java.jar lib/optimization.jar lib/parallelcolt.jar
lib/phys2d.jar lib/sound.jar lib/substance.jar lib/substance-flamingo.jar
lib/substance-swingx.jar lib/swingx-all.jar lib/Tracking.jar lib/trident.jar
lib/vecmath.jar lib/vtk.jar lib/xuggler.jar
Expand Down
2 changes: 1 addition & 1 deletion icy/main/Icy.java
Expand Up @@ -98,7 +98,7 @@ public class Icy
/**
* ICY Version
*/
public static Version version = new Version("1.8.5.1");
public static Version version = new Version("1.8.5.2");

/**
* Main interface
Expand Down
103 changes: 103 additions & 0 deletions icy/roi/ROIDescriptor.java
Expand Up @@ -3,11 +3,23 @@
*/
package icy.roi;

import icy.plugin.PluginDescriptor;
import icy.plugin.PluginLauncher;
import icy.plugin.PluginLoader;
import icy.plugin.interface_.PluginROIDescriptor;
import icy.roi.ROIEvent.ROIEventType;
import icy.sequence.Sequence;
import icy.sequence.SequenceEvent;
import icy.system.IcyExceptionHandler;
import icy.util.StringUtil;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import plugins.kernel.roi.descriptor.measure.ROIBasicMeasureDescriptorsPlugin;

/**
* Abstract class providing the basic methods to retrieve properties and compute a specific
* descriptor for a region of interest (ROI)
Expand All @@ -16,6 +28,97 @@
*/
public abstract class ROIDescriptor
{
/**
* Returns all available ROI descriptors (see {@link ROIDescriptor}) and their attached plugin
* (see {@link PluginROIDescriptor}).<br/>
* This list can be extended by installing new plugin(s) implementing the {@link PluginROIDescriptor} interface.
*
* @see ROIDescriptor#compute(ROI, Sequence)
* @see PluginROIDescriptor#compute(ROI, Sequence)
*/
public static Map<ROIDescriptor, PluginROIDescriptor> getDescriptors()
{
final Map<ROIDescriptor, PluginROIDescriptor> result = new HashMap<ROIDescriptor, PluginROIDescriptor>();
final List<PluginDescriptor> pluginDescriptors = PluginLoader.getPlugins(PluginROIDescriptor.class);

for (PluginDescriptor pluginDescriptor : pluginDescriptors)
{
try
{
final PluginROIDescriptor plugin = (PluginROIDescriptor) PluginLauncher.create(pluginDescriptor);
final List<ROIDescriptor> descriptors = plugin.getDescriptors();

if (descriptors != null)
{
for (ROIDescriptor roiDescriptor : descriptors)
result.put(roiDescriptor, plugin);
}
}
catch (Throwable e)
{
// show a message in the output console
IcyExceptionHandler.showErrorMessage(e, false, true);
// and send an error report (silent as we don't want a dialog appearing here)
IcyExceptionHandler.report(pluginDescriptor, IcyExceptionHandler.getErrorMessage(e, true));
}
}

return result;
}

/**
* Computes the specified descriptor from the input {@link ROIDescriptor} set on given ROI
* and returns the result (or <code>null</code> if the descriptor is not found).
*
* @param roiDescriptors
* the input {@link ROIDescriptor} set (see {@link #getDescriptors()} method)
* @param descriptorId
* the id of the descriptor we want to compute ({@link ROIBasicMeasureDescriptorsPlugin#ID_VOLUME} for
* instance)
* @param roi
* the ROI on which the descriptor(s) should be computed
* @param sequence
* an optional sequence where the pixel size can be retrieved
* @return the computed descriptor or <code>null</code> if the descriptor if not found in the
* specified set
* @throws UnsupportedOperationException
* if the type of the given ROI is not supported by this descriptor, or if <code>sequence</code> is
* <code>null</code> while the calculation requires it, or if
* the specified Z, T or C position are not supported by the descriptor
*/
public static Object computeDescriptor(Set<ROIDescriptor> roiDescriptors, String descriptorId, ROI roi,
Sequence sequence)
{
for (ROIDescriptor roiDescriptor : roiDescriptors)
if (StringUtil.equals(roiDescriptor.getId(), descriptorId))
return roiDescriptor.compute(roi, sequence);

return null;
}

/**
* Computes the specified descriptor on given ROI and returns the result (or <code>null</code> if the descriptor is
* not found).
*
* @param descriptorId
* the id of the descriptor we want to compute ({@link ROIBasicMeasureDescriptorsPlugin#ID_VOLUME} for
* instance)
* @param roi
* the ROI on which the descriptor(s) should be computed
* @param sequence
* an optional sequence where the pixel size can be retrieved
* @return the computed descriptor or <code>null</code> if the descriptor if not found in the
* specified set
* @throws UnsupportedOperationException
* if the type of the given ROI is not supported by this descriptor, or if <code>sequence</code> is
* <code>null</code> while the calculation requires it, or if
* the specified Z, T or C position are not supported by the descriptor
*/
public static Object computeDescriptor(String descriptorId, ROI roi, Sequence sequence)
{
return computeDescriptor(getDescriptors().keySet(), descriptorId, roi, sequence);
}

protected final String id;
protected final String name;
protected final Class<?> type;
Expand Down
44 changes: 9 additions & 35 deletions icy/roi/ROIUtil.java
Expand Up @@ -70,44 +70,21 @@ public class ROIUtil
/**
* Returns all available ROI descriptors (see {@link ROIDescriptor}) and their attached plugin
* (see {@link PluginROIDescriptor}).<br/>
* This list can be extended by installing new plugin(s) implementing the {@link PluginROIDescriptor} interface.
* This list can be extended by installing new plugin(s) implementing the {@link PluginROIDescriptor} interface.<br/>
* This method is an alias of {@link ROIDescriptor#getDescriptors()}
*
* @see ROIDescriptor#compute(ROI, Sequence)
* @see PluginROIDescriptor#compute(ROI, Sequence)
*/
public static Map<ROIDescriptor, PluginROIDescriptor> getROIDescriptors()
{
final Map<ROIDescriptor, PluginROIDescriptor> result = new HashMap<ROIDescriptor, PluginROIDescriptor>();
final List<PluginDescriptor> pluginDescriptors = PluginLoader.getPlugins(PluginROIDescriptor.class);

for (PluginDescriptor pluginDescriptor : pluginDescriptors)
{
try
{
final PluginROIDescriptor plugin = (PluginROIDescriptor) PluginLauncher.create(pluginDescriptor);
final List<ROIDescriptor> descriptors = plugin.getDescriptors();

if (descriptors != null)
{
for (ROIDescriptor roiDescriptor : descriptors)
result.put(roiDescriptor, plugin);
}
}
catch (Throwable e)
{
// show a message in the output console
IcyExceptionHandler.showErrorMessage(e, false, true);
// and send an error report (silent as we don't want a dialog appearing here)
IcyExceptionHandler.report(pluginDescriptor, IcyExceptionHandler.getErrorMessage(e, true));
}
}

return result;
return ROIDescriptor.getDescriptors();
}

/**
* Computes the specified descriptor from the input {@link ROIDescriptor} set on given ROI
* and returns the result (or <code>null</code> if the descriptor is not found).
* and returns the result (or <code>null</code> if the descriptor is not found).<br/>
* This method is an alias of {@link ROIDescriptor#computeDescriptor(Set, String, ROI, Sequence)}
*
* @param roiDescriptors
* the input {@link ROIDescriptor} set (see {@link #getROIDescriptors()} method)
Expand All @@ -128,16 +105,13 @@ public static Map<ROIDescriptor, PluginROIDescriptor> getROIDescriptors()
public static Object computeDescriptor(Set<ROIDescriptor> roiDescriptors, String descriptorId, ROI roi,
Sequence sequence)
{
for (ROIDescriptor roiDescriptor : roiDescriptors)
if (StringUtil.equals(roiDescriptor.getId(), descriptorId))
return roiDescriptor.compute(roi, sequence);

return null;
return ROIDescriptor.computeDescriptor(roiDescriptors, descriptorId, roi, sequence);
}

/**
* Computes the specified descriptor on given ROI and returns the result (or <code>null</code> if the descriptor is
* not found).
* not found).<br/>
* This method is an alias of {@link ROIDescriptor#computeDescriptor(String, ROI, Sequence)}
*
* @param descriptorId
* the id of the descriptor we want to compute ({@link ROIBasicMeasureDescriptorsPlugin#ID_VOLUME} for
Expand All @@ -155,7 +129,7 @@ public static Object computeDescriptor(Set<ROIDescriptor> roiDescriptors, String
*/
public static Object computeDescriptor(String descriptorId, ROI roi, Sequence sequence)
{
return computeDescriptor(getROIDescriptors().keySet(), descriptorId, roi, sequence);
return ROIDescriptor.computeDescriptor(descriptorId, roi, sequence);
}

/**
Expand Down
102 changes: 97 additions & 5 deletions icy/sequence/MetaDataUtil.java
Expand Up @@ -234,16 +234,36 @@ public static Plane ensurePlane(Pixels pix, int t, int z, int c)
}

/**
* Remove the Plan at specified position
* Remove the Plan at specified position.
*
* @return <code>true</code> if the operation succeed, <code>false</code> otherwise
*/
public static void removePlane(Image img, int t, int z, int c)
public static boolean removePlane(Image img, int t, int z, int c)
{
final Pixels pix = img.getPixels();
if (pix == null)
return;
return false;

return removePlane(img, getPlaneIndex(pix, t, z, c));
}

/**
* Remove the Plan at specified position.
*
* @return <code>true</code> if the operation succeed, <code>false</code> otherwise
*/
public static boolean removePlane(Image img, int index)
{
final Pixels pix = img.getPixels();
if (pix == null)
return false;

final int numPlane = pix.sizeOfPlaneList();
final int index = getPlaneIndex(pix, t, z, c);

// no plane here --> return false
if (index >= numPlane)
return false;

final Plane plane = getPlane(pix, index);

// remove plane
Expand All @@ -258,6 +278,8 @@ public static void removePlane(Image img, int t, int z, int c)
pix.removeBinData(pix.getBinData(index));
if (pix.sizeOfTiffDataList() == numPlane)
pix.removeTiffData(pix.getTiffData(index));

return true;
}

/**
Expand Down Expand Up @@ -896,7 +918,12 @@ public static void setMetaData(OMEXMLMetadataImpl metadata, int sizeX, int sizeY

// keep only one image
setNumSerie(metadata, 1);
// we need to remove some plane data
// clean TiffData metadata (can produce error on reloading)
cleanTiffData(ome.getImage(0));
// clean binData metadata (can produce error on reloading)
cleanBinData(ome.getImage(0));

// we need to remove some plane data (normally here we have sizeZ = 1 and sizeT = 1)
if ((z != -1) || (t != -1))
keepPlanes(ome.getImage(0), t, z, -1);

Expand All @@ -922,6 +949,9 @@ public static void setMetaData(OMEXMLMetadataImpl metadata, int sizeX, int sizeY
metadata.setPixelsSizeZ(OMEUtil.getPositiveInteger(sizeZ), 0);
metadata.setPixelsSizeT(OMEUtil.getPositiveInteger(sizeT), 0);

// clean plane metadata outside allowed range
cleanPlanes(ome.getImage(0));

// get time interval information
double timeInterval = MetaDataUtil.getTimeInterval(metadata, 0, 0d);
// not defined ?
Expand Down Expand Up @@ -1309,6 +1339,8 @@ else if (img.sizeOfLinkedAnnotationList() == numPlane)
/**
* Keep only plane(s) at specified C, Z, T position from the given metadata.
*
* @param img
* image metadata to clean plane from
* @param posT
* keep Plane to given T position (-1 to keep all)
* @param posZ
Expand Down Expand Up @@ -1345,6 +1377,66 @@ public static void keepPlanes(Image img, int posT, int posZ, int posC)
}
}

/**
* Clean plane(s) which are outside the pixel sizeC / sizeZ and sizeT.
*
* @param img
* image metadata to clean plane from
*/
public static void cleanPlanes(Image img)
{
final Pixels pix = img.getPixels();
if (pix == null)
return;

final int sizeT = OMEUtil.getValue(pix.getSizeT(), 0);
final int sizeZ = OMEUtil.getValue(pix.getSizeZ(), 0);
final int sizeC = OMEUtil.getValue(pix.getSizeC(), 0);
if ((sizeT < 1) || (sizeZ < 1) || (sizeC < 1))
return;

// get allowed maximum plane
final int allowedMaxPlaneIndex = getPlaneIndex(pix, sizeT - 1, sizeZ - 1, sizeC - 1);
// current number of plane
int maxPlaneIndex = pix.sizeOfPlaneList() - 1;

// remove plan outside allowed region
while (maxPlaneIndex > allowedMaxPlaneIndex)
removePlane(img, maxPlaneIndex--);
}

/**
* Clean TiffData packet
*
* @param img
* image metadata to clean TiffData from
*/
public static void cleanTiffData(Image img)
{
final Pixels pix = img.getPixels();
if (pix == null)
return;

while (pix.sizeOfTiffDataList() > 0)
pix.removeTiffData(pix.getTiffData(pix.sizeOfTiffDataList() - 1));
}

/**
* Clean BinData packet
*
* @param img
* image metadata to clean BinData from
*/
public static void cleanBinData(Image img)
{
final Pixels pix = img.getPixels();
if (pix == null)
return;

while (pix.sizeOfBinDataList() > 0)
pix.removeBinData(pix.getBinData(pix.sizeOfBinDataList() - 1));
}

/**
* Cleanup the meta data (sometime we have empty data structure sitting there)
*/
Expand Down
Expand Up @@ -41,11 +41,11 @@ public class ROIIntensityDescriptorsPlugin extends Plugin implements PluginROIDe

public static class IntensityDescriptorInfos
{
double min;
double mean;
double max;
double sum;
double deviation;
public double min;
public double mean;
public double max;
public double sum;
public double deviation;
};

/**
Expand All @@ -59,8 +59,7 @@ public static class IntensityDescriptorInfos
* the Sequence used to compute the intensity descriptors
* @param allowMultiChannel
* Allow multi channel intensity computation. If this parameter is set to <code>false</code> and the ROI
* number of channel
* is > 1 then a {@link UnsupportedOperationException} is launch.
* number of channel is > 1 then a {@link UnsupportedOperationException} is launch.
* @throws Exception
* If the ROI dimension changed during the descriptor computation.
* @throws UnsupportedOperationException
Expand Down

0 comments on commit ffa46c2

Please sign in to comment.