开发者

Median Filter a bi-level image with JAI

I'd like to apply a Median Filter to a bi-level image and output a bi-level image. The JAI median filter seems to output an RGB image, which I'm having trouble downconverting back to bi-level.

Currently I can't even get the image back into gray color-space, my code lo开发者_运维知识库oks like this:

BufferedImage src; // contains a bi-level image

ParameterBlock pb = new ParameterBlock();
pb.addSource(src);
pb.add(MedianFilterDescriptor.MEDIAN_MASK_SQUARE);
pb.add(3);
RenderedOp result = JAI.create("MedianFilter", pb);

ParameterBlock pb2 = new ParameterBlock();
pb2.addSource(result);
pb2.add(new double[][]{{0.33, 0.34, 0.33, 0}});
RenderedOp grayResult = JAI.create("BandCombine", pb2);

BufferedImage foo = grayResult.getAsBufferedImage();

This code hangs on the grayResult line and appears not to return. I assume that I'll eventually need to call the "Binarize" operation in JAI.

Edit: Actually, the code appears to be stalling once I call getAsBufferedImage(), but returns nearly instantly when the second operation ("BandCombine") is removed.

Is there a better way to keep the Median Filtering in the source color domain? If not, how do I downconvert back to binary?


Unfortunately it seems like the BandCombine operation doesn't behave as expected here. The appropriate tactic for getting back to bilevel is to use a flavor of ColorConvertOp -- doing so enables use of the MedianFilter operation which will (again, unfortunately) always lead to an RGB image.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜