From 187ddbeedbc77ccdcd201a76c1c8b53113b8354a Mon Sep 17 00:00:00 2001
From: ctrebeau <ctrebeau@pasteur.fr>
Date: Tue, 12 Nov 2024 11:12:45 +0100
Subject: [PATCH] Bug fix - Avoid NPE when the ImfFactory is a CellIMgFactory
 with null reader (https://github.com/scifio/scifio/issues/476)

---
 .../zellige/steps/selection/pretreatment/Pretreatment.java  | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/main/java/fr/pasteur/ida/zellige/steps/selection/pretreatment/Pretreatment.java b/src/main/java/fr/pasteur/ida/zellige/steps/selection/pretreatment/Pretreatment.java
index c373350..c951595 100644
--- a/src/main/java/fr/pasteur/ida/zellige/steps/selection/pretreatment/Pretreatment.java
+++ b/src/main/java/fr/pasteur/ida/zellige/steps/selection/pretreatment/Pretreatment.java
@@ -44,6 +44,7 @@ import net.imglib2.type.numeric.RealType;
 import net.imglib2.type.numeric.integer.UnsignedByteType;
 import net.imglib2.type.numeric.real.FloatType;
 import net.imglib2.util.ImgUtil;
+import net.imglib2.util.Util;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -134,7 +135,8 @@ public class Pretreatment< T extends RealType< T > & NativeType< T > >
      */
     private static < T extends RealType< T > & NativeType< T > > Img< FloatType > gaussianBlurFilterDenoising( RandomAccessibleInterval< T > input, ImgFactory< T > factory, double radius )
     {
-        ImgFactory< FloatType > newImgFactory = factory.imgFactory( new FloatType() );
+        Dimensions dimensions = new FinalDimensions( input.dimension( 0 ), input.dimension( 1 ), input.dimension( 2 ) );
+        ImgFactory< FloatType > newImgFactory = Util.getArrayOrCellImgFactory(dimensions, new FloatType());
         Img< FloatType > output = newImgFactory.create( input.dimensionsAsLongArray() );
         Utils.gaussianConvolution_( input, output, new double[]{ radius, radius, 1 } );
         return output;
@@ -168,7 +170,7 @@ public class Pretreatment< T extends RealType< T > & NativeType< T > >
             }
         }
 
-        Img< UnsignedByteType > output_unbinned = Unbinning.run( i, i.factory(), bin );
+        Img< UnsignedByteType > output_unbinned = Unbinning.run( i,  bin );
         ImageJFunctions.show( output_unbinned, "unbinned 1" );
     }
 }
-- 
GitLab