From d59f8aca332ef72ec2317cfb159c5711bc279551 Mon Sep 17 00:00:00 2001 From: Albert Cardona Date: Sat, 4 Apr 2009 01:26:26 +0200 Subject: [PATCH] Fixed alpha mask storing issue: parent folders where not being created, and would fail with a bizarre alert message from the FileSaver. Also the mask as read from the file is not returned if it has mismatching dimensions with the Patch o_width,o_height, which would make the mipmap generation fail. --- ini/trakem2/persistence/FSLoader.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/ini/trakem2/persistence/FSLoader.java b/ini/trakem2/persistence/FSLoader.java index 8b218b59..5d55c163 100644 --- a/ini/trakem2/persistence/FSLoader.java +++ b/ini/trakem2/persistence/FSLoader.java @@ -619,10 +619,16 @@ public final class FSLoader extends Loader { // Open the mask image, which should be a compressed float tif. final ImagePlus imp = opener.openImage(path); if (null == imp) { - Utils.log2("No mask found or could not open mask image for patch " + p + " from " + path); + //Utils.log2("No mask found or could not open mask image for patch " + p + " from " + path); return null; } - return (ByteProcessor)imp.getProcessor().convertToByte(false); + final ByteProcessor mask = (ByteProcessor)imp.getProcessor().convertToByte(false); + //Utils.log2("Mask dimensions: " + mask.getWidth() + " x " + mask.getHeight() + " for patch " + p); + if (mask.getWidth() != p.getOWidth() || mask.getHeight() != p.getOHeight()) { + Utils.log2("Mask has improper dimensions: " + mask.getWidth() + " x " + mask.getHeight() + " for patch " + p + " which is of " + p.getOWidth() + " x " + p.getOHeight()); + return null; + } + return mask; } @Override @@ -639,6 +645,10 @@ public final class FSLoader extends Loader { @Override public void storeAlphaMask(final Patch p, final ByteProcessor fp) { // would fail if user deletes the trakem2.masks/ folder from the storage folder after having set dir_masks. But that is his problem. + final String path = getAlphaPath(p); + File parent = new File(path).getParentFile(); + parent.mkdirs(); + IJ.redirectErrorMessages(); new FileSaver(new ImagePlus("mask", fp)).saveAsZip(getAlphaPath(p)); } @@ -1774,6 +1784,9 @@ public final class FSLoader extends Loader { } do { + +//Utils.logAll("### k=" + k + " alpha.length=" + (null != alpha ? ((float[])alpha.getPixels()).length : 0) + " image.length=" + ((float[])fp.getPixels()).length); + if (Thread.currentThread().isInterrupted()) return false; // 0 - blur the previous image to 0.75 sigma -- 2.11.4.GIT