Skip to content
Snippets Groups Projects
Commit b677b148 authored by jakubs's avatar jakubs
Browse files

SP-958 BIS-557 include filename in error message in some known image-reading error scenarios

SVN: 29953
parent 2fc258a1
No related branches found
No related tags found
No related merge requests found
......@@ -39,6 +39,7 @@ import ch.systemsx.cisd.common.concurrent.ITaskExecutor;
import ch.systemsx.cisd.common.concurrent.ParallelizedExecutor;
import ch.systemsx.cisd.common.exceptions.EnvironmentFailureException;
import ch.systemsx.cisd.common.exceptions.Status;
import ch.systemsx.cisd.common.exceptions.UserFailureException;
import ch.systemsx.cisd.common.filesystem.FileUtilities;
import ch.systemsx.cisd.common.logging.LogCategory;
import ch.systemsx.cisd.common.logging.LogFactory;
......@@ -534,14 +535,20 @@ public class Hdf5ThumbnailGenerator implements IHDF5WriterClient
private BufferedImage loadUnchangedImage(String imageRelativePath, String imageIdOrNull)
{
if (contentOrNull == null)
try
{
return Utils.loadUnchangedImage(new FileBasedContentNode(new File(
imagesParentDirectory, imageRelativePath)), imageIdOrNull, imageLibraryOrNull);
} else
if (contentOrNull == null)
{
return Utils.loadUnchangedImage(new FileBasedContentNode(new File(
imagesParentDirectory, imageRelativePath)), imageIdOrNull, imageLibraryOrNull);
} else
{
return Utils.loadUnchangedImage(contentOrNull.getNode(imageRelativePath),
imageIdOrNull, imageLibraryOrNull);
}
} catch (Exception ex)
{
return Utils.loadUnchangedImage(contentOrNull.getNode(imageRelativePath),
imageIdOrNull, imageLibraryOrNull);
throw new UserFailureException("Failed to load image " + imageRelativePath, ex);
}
}
......
......@@ -499,17 +499,22 @@ public class ImagingDataSetRegistrationTransaction extends DataSetRegistrationTr
private void setBoundingBox(ImageDataSetInformation imageDataSetInformation,
IHierarchicalContentNode content, ImageLibraryInfo imageLibrary)
{
Size size = Utils.loadUnchangedImageSize(content, null, imageLibrary);
imageDataSetInformation.setMaximumImageWidth(Math.max(
imageDataSetInformation.getMaximumImageWidth(), size.getWidth()));
imageDataSetInformation.setMaximumImageHeight(Math.max(
imageDataSetInformation.getMaximumImageHeight(), size.getHeight()));
if (imageDataSetInformation.getColorDepth() == null)
{
imageDataSetInformation.setColorDepth(Utils.loadUnchangedImageColorDepth(content, null,
imageLibrary));
try
{
Size size = Utils.loadUnchangedImageSize(content, null, imageLibrary);
imageDataSetInformation.setMaximumImageWidth(Math.max(
imageDataSetInformation.getMaximumImageWidth(), size.getWidth()));
imageDataSetInformation.setMaximumImageHeight(Math.max(
imageDataSetInformation.getMaximumImageHeight(), size.getHeight()));
if (imageDataSetInformation.getColorDepth() == null)
{
imageDataSetInformation.setColorDepth(Utils.loadUnchangedImageColorDepth(content, null,
imageLibrary));
}
} catch (Exception ex)
{
throw new UserFailureException("Error ocured when calculating bounding box of " + content.getRelativePath(), ex);
}
}
private File prependOriginalDirectory(String directoryPath)
......
......@@ -258,15 +258,21 @@ public class SimpleImageDataSetRegistrator
for (File imageFile : imageFiles)
{
File file = new File(imageFile.getPath());
List<ImageIdentifier> identifiers = getImageIdentifiers(imageReaderOrNull, file);
String imageRelativePath = FileUtilities.getRelativeFilePath(incomingDirectory, file);
ImageMetadata[] imageTokens =
simpleImageConfig.extractImagesMetadata(imageRelativePath, identifiers);
for (ImageMetadata imageToken : imageTokens)
try
{
imageToken.ensureValid(simpleImageConfig.isMicroscopyData());
imageTokensList.add(new ImageTokensWithPath(imageToken, imageRelativePath));
File file = new File(imageFile.getPath());
List<ImageIdentifier> identifiers = getImageIdentifiers(imageReaderOrNull, file);
String imageRelativePath = FileUtilities.getRelativeFilePath(incomingDirectory, file);
ImageMetadata[] imageTokens =
simpleImageConfig.extractImagesMetadata(imageRelativePath, identifiers);
for (ImageMetadata imageToken : imageTokens)
{
imageToken.ensureValid(simpleImageConfig.isMicroscopyData());
imageTokensList.add(new ImageTokensWithPath(imageToken, imageRelativePath));
}
} catch (Exception ex)
{
throw new UserFailureException("Error ocured when processing image " + imageFile.getPath(), ex);
}
}
if (imageTokensList.isEmpty())
......@@ -589,20 +595,26 @@ public class SimpleImageDataSetRegistrator
for (File imageFile : imageFiles)
{
List<ImageIdentifier> imageIdentifiers = getImageIdentifiers(readerOrNull, imageFile);
for (ImageIdentifier imageIdentifier : imageIdentifiers)
try
{
BufferedImage image =
loadUnchangedImage(imageFile, imageIdentifier, libraryName, readerName);
if (IntensityRescaling.isNotGrayscale(image))
List<ImageIdentifier> imageIdentifiers = getImageIdentifiers(readerOrNull, imageFile);
for (ImageIdentifier imageIdentifier : imageIdentifiers)
{
operationLog
.warn(String
.format("Intensity range cannot be computed because image '%s' is not in grayscale.",
imageFile.getPath()));
return null;
BufferedImage image =
loadUnchangedImage(imageFile, imageIdentifier, libraryName, readerName);
if (IntensityRescaling.isNotGrayscale(image))
{
operationLog
.warn(String
.format("Intensity range cannot be computed because image '%s' is not in grayscale.",
imageFile.getPath()));
return null;
}
IntensityRescaling.addToLevelStats(histogram, image);
}
IntensityRescaling.addToLevelStats(histogram, image);
} catch (Exception ex)
{
throw new UserFailureException("Error ocured when processing image " + imageFile.getPath(), ex);
}
}
return IntensityRescaling.computeLevels(histogram, threshold);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment