thresholdingfilter.java

来自「some of the image proceeing samples usin」· Java 代码 · 共 35 行

JAVA
35
字号
package image.filter;

import image.EditableImage;
import image.ImagingUtils;

public class ThresholdingFilter extends AbstractFilter {
    
    public ThresholdingFilter(EditableImage image) {
        super(image);
    }
    
    
    public void processFilter() {
        
        int threshold = ((Integer)getParameter("threshold")).intValue();
        
        if (threshold > 0 && threshold <= 255) {
        
            int width = image.getWidth();
            int height = image.getHeight();

            for (int h = 0; h < height; h++) {
                for (int w = 0; w < width; w++) {

                    image.getImage().setRGB(w, h, thresholdPixel(image.getImage().getRGB(w, h), threshold));
                }
            }
        }
    }
    
    private int thresholdPixel(int pixel, int threshold) {
        return ImagingUtils.convertPixel((((ImagingUtils.convertToGrayscale(pixel) & 0x00FF0000) >>> 16) > threshold) ? 255 : 0);
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?