@@ -223,7 +223,10 @@ public void run(String arg) {
223223 RandomAccessibleInterval <UnsignedShortType > samJReturnMask (RandomAccessibleInterval <T > rai ,
224224 List <int []> pointPrompts ,
225225 List <Rectangle > rectPrompts ) throws IOException , RuntimeException , InterruptedException {
226- return samJReturnMask (new SAM2Tiny (), rai , pointPrompts , rectPrompts );
226+ SAM2Tiny model = new SAM2Tiny ();
227+ RandomAccessibleInterval <UnsignedShortType > res = samJReturnMask (model , rai , pointPrompts , rectPrompts );
228+ model .closeProcess ();
229+ return res ;
227230 }
228231
229232 /**
@@ -294,7 +297,10 @@ RandomAccessibleInterval<UnsignedShortType> samJReturnMask(SAMModel model, Rando
294297 */
295298 public static < T extends RealType < T > & NativeType < T > >
296299 List <Mask > samJReturnContours (RandomAccessibleInterval <T > rai , List <int []> pointPrompts , List <Rectangle > rectPrompts ) throws IOException , RuntimeException , InterruptedException {
297- return samJReturnContours (new SAM2Tiny (), rai , pointPrompts , rectPrompts );
300+ SAM2Tiny model = new SAM2Tiny ();
301+ List <Mask > res = samJReturnContours (model , rai , pointPrompts , rectPrompts );
302+ model .closeProcess ();
303+ return res ;
298304 }
299305
300306 /**
@@ -340,8 +346,7 @@ List<Mask> samJReturnContours(SAMModel model, RandomAccessibleInterval<T> rai, L
340346 if (selected == null )
341347 throw new IllegalArgumentException ("Specified model does not exist. Please, for more info visit: "
342348 + MACRO_INFO );
343- selected .loadModel (null );
344- selected .setImage (rai );
349+ selected .setImage (rai , null );
345350 selected .setReturnOnlyBiggest (true );
346351 RandomAccessibleInterval <T > maskRai = null ;
347352 List <Mask > callbackedContours = new ArrayList <Mask >();
@@ -364,7 +369,6 @@ public void deleteRectPrompt(List<int[]> promptList) {}
364369 callbackedContours .addAll (contours );
365370
366371
367- selected .closeProcess ();
368372 return callbackedContours ;
369373 }
370374
@@ -402,8 +406,7 @@ void macroRunSAMJ() throws IOException, RuntimeException, InterruptedException {
402406 + MACRO_INFO );
403407 MACRO_CONSUMER .setModel (selected );
404408 RandomAccessibleInterval <T > rai = MACRO_CONSUMER .getFocusedImageAsRai ();
405- selected .loadModel (null );
406- selected .setImage (rai );
409+ selected .setImage (rai , null );
407410 selected .setReturnOnlyBiggest (true );
408411 List <int []> pointPrompts = MACRO_CONSUMER .getPointRoisOnFocusImage ();
409412 List <Rectangle > rectPrompts = MACRO_CONSUMER .getRectRoisOnFocusImage ();
0 commit comments