@Test
public void testArtifact() throws IOException{
TIFFImageReaderSpi spi = new TIFFImageReaderSpi();
File file = TestData.file(this, "filter.tif");
ImageReader reader = null;
FileImageInputStream fis = null;
try {
fis = new FileImageInputStream(file);
reader = spi.createReaderInstance();
reader.setInput(fis);
RenderedImage image = reader.read(0);
RenderedOp histogramOp = HistogramDescriptor.create(image, null, Integer.valueOf(1), Integer.valueOf(1), new int[]{256}, null, null, null);
Histogram histogram = (Histogram) histogramOp.getProperty("histogram");
int[][] bins = histogram.getBins();
assertEquals(bins[0][0],4261);
assertEquals(bins[1][0],4261);
assertEquals(bins[2][0],4832);
assertEquals(bins[0][20],127); // This bin will disappear in the Histogram of the filtered image
assertEquals(bins[1][20],127); // This bin will disappear in the Histogram of the filtered image
assertEquals(bins[2][20],127); // This bin will disappear in the Histogram of the filtered image
assertEquals(bins[0][180],571);
assertEquals(bins[0][200],5041);
assertEquals(bins[2][200],5041);
assertEquals(bins[1][255],5612);
assertEquals(bins[0][0]+bins[1][0]+bins[2][0]+bins[0][20]+bins[1][20]+bins[2][20]+bins[0][180]+bins[0][200]+bins[2][200]+bins[1][255], 100*100*3);
// Image filtering
ROI roi = new ROIShape(new Rectangle(14, 11, 75, 75));
double [] backgroundValues = new double[]{0.0d, 0.0d, 0.0d};
RenderedImage filtered = ArtifactsFilterDescriptor.create(image, roi, backgroundValues, 30, 3, null);
histogramOp = HistogramDescriptor.create(filtered, null, Integer.valueOf(1), Integer.valueOf(1), new int[]{256}, null, null, null);
histogram = (Histogram) histogramOp.getProperty("histogram");
bins = histogram.getBins();
assertEquals(bins[0][0],4261);
assertEquals(bins[1][0],4261);
assertEquals(bins[2][0],4845);
assertEquals(bins[0][180],584);
assertEquals(bins[0][200],5041);
assertEquals(bins[2][200],5041);
assertEquals(bins[1][255],5625);
assertEquals(bins[0][0]+bins[1][0]+bins[2][0]+bins[0][20]+bins[1][20]+bins[2][20] +bins[0][180]+bins[0][200]+bins[2][200]+bins[1][255], 100*100*3);
} finally {
if (fis != null){
try {
fis.close();
} catch (Throwable t){
}
}
if (reader != null){