/*=========================================================================
 *
 *  Copyright Insight Software Consortium
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0.txt
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 *=========================================================================*/

package plugins.ITK;

import icy.gui.frame.progress.AnnounceFrame;
import icy.image.IcyBufferedImage;
import icy.plugin.abstract_.Plugin;
import icy.plugin.interface_.PluginImageAnalysis;
import icy.sequence.Sequence;

import org.itk.simple.BinaryErodeImageFilter;
import org.itk.simple.BinaryThresholdImageFilter;
import org.itk.simple.Image;
import org.itk.simple.PixelContainer;
import org.itk.simple.PixelIDValueEnum;

/**
 *
 * This plugins applies a binary threshold to the input image.
 *
 */
public class BinaryThresholdPlugin extends Plugin implements PluginImageAnalysis {

  /**
   * This method will be called as the user click on the plugin button.
   */
  @Override
  public void compute() {

    new AnnounceFrame("Hello ICY + ITK !");

    IcyBufferedImage icyImage = getFocusedImage();

    byte[] dataBuffer = icyImage.getDataXYAsByte(0);

    PixelIDValueEnum pixelID = PixelIDValueEnum.sitkUInt8;

    Image inputImage = new Image( icyImage.getSizeX(), icyImage.getSizeY(), pixelID );

    PixelContainer pixelContainer = inputImage.getPixelContainer();

    int numberOfPixels = icyImage.getSizeX() * icyImage.getSizeY();

    // pixelContainer.setBufferAsInt8( dataBuffer, numberOfPixels );

    BinaryThresholdImageFilter thresholder = new BinaryThresholdImageFilter();

    thresholder.setLowerThreshold(10);
    thresholder.setUpperThreshold(100);

    Image output1 = thresholder.execute( inputImage );

    BinaryErodeImageFilter eroder = new BinaryErodeImageFilter();

    Image output2 = eroder.execute( output1 );

    PixelContainer pixelsContainerOutput = output2.getPixelContainer();

    // dataBuffer = pixelsContainerOutput.getBufferAsUnsignedInt8();

    icyImage.setDataXYAsByte(0,dataBuffer);

    Sequence sequence = new Sequence("Byte Image",icyImage);

    addSequence(sequence);

  }

}

@@ -987,16 +987,42 @@
 equence;
+%0Aimport icy.type.TypeUtil;
 %0A%0Aimport
@@ -1162,28 +1162,31 @@
 .simple.
-PixelContain
+ImportImageFilt
 er;%0Aimpo
@@ -1611,151 +1611,87 @@
     
-byte%5B%5D dataBuffer = icyImage.getDataXYAsByte(0);%0A%0A    PixelIDValueEnum pixelID = PixelIDValueEnum.sitkUInt8;%0A%0A    Image inputImage = new Image(
+ImportImageFilter importer = new ImportImageFilter();%0A%0A    int numberOfPixels =
  icy
@@ -1706,17 +1706,18 @@
 tSizeX()
-,
+ *
  icyImag
@@ -1732,234 +1732,332 @@
 eY()
-, pixelID );%0A%0A    PixelContainer pixelContainer = inputImage.getPixelContainer();%0A%0A    int numberOfPixels = icyImage.getSizeX() * icyImage.getSizeY();%0A%0A    // pixelContainer.setBufferAsInt8( dataBuffer, numberOfPixels 
+;%0A    %0A    //%0A    //  Transfer image from ICY to ITK%0A    //%0A    switch ( icyImage.getDataType() )%0A    %7B%0A        case TypeUtil.TYPE_BYTE:%0A        %7B%0A        byte%5B%5D dataBuffer = icyImage.getDataXYAsByte(0);%0A%0A        // connect here the buffer to the importer%0A        %7D%0A    %7D%0A   %09Image inputImage = importer.execute(
 );%0A
-%0A
    
- 
+%09%0A   %09
 Bina
@@ -2127,25 +2127,25 @@
 lter();%0A%0A   
- 
+%09
 thresholder.
@@ -2170,17 +2170,17 @@
 10);%0A   
- 
+%09
 threshol
@@ -2207,25 +2207,25 @@
 d(100);%0A%0A   
- 
+%09
 Image output
@@ -2267,17 +2267,17 @@
  );%0A%0A   
- 
+%09
 BinaryEr
@@ -2334,17 +2334,17 @@
 ();%0A%0A   
- 
+%09
 Image ou
@@ -2382,123 +2382,263 @@
  );%0A
-%0A    PixelContainer pixelsContainerOutput = output2.getPixelContainer();%0A
+    %09%0A   %09//%0A   %09// Transfer image from ITK to ICY%0A   %09//%0A%09switch ( icyImage.getDataType() )%0A    %7B%0A        case TypeUtil.TYPE_BYTE:%0A        %7B%0A%0A        byte%5B%5D outputDataBuffer = icyImage.getDataXYAsByte(0); // FIXME
 %0A    
+%09
 //
- dataBuffer = pixelsContainerO
+byte%5B%5D outputDataBuffer = o
 utput
+2
 .get
@@ -2666,16 +2666,17 @@
 );%0A%0A    
+%09
 icyImage
@@ -2696,23 +2696,60 @@
 yte(
-0,dataBuffer);%0A
+numberOfPixels,outputDataBuffer);%0A        %7D%0A    %7D%0A%0A%09
 %0A   

Introduce ImportImageFilter.