java图像处理——图像读取,二值化转bitset

最近要处理一些新闻中的广告图片,其中比较多的是含二维码的图片。简单写了3种逻辑处理了下(同源不同内容,同图片;含完整二维码的图片;残缺二维码广告图片),基本达到了实际需求。有同样需求的可以参考下,言归正传,今天看到有读者问java图像怎么转bitset,下面举例一些我的处理方法。
首先图片有不同来源,有的是url,那么url首先读取成BufferedImage

URL url_url = new URL(img_url);
Image image = null;
try
{
    image = ImageIO.read(url_url);
} catch (Exception e)
{
    e.printStackTrace();

}
BufferedImage buf = GetImage.toBufferedImage(image);
BufferedImage binatryBuf = BinaryTest.loaclTOBinatry(buf);
ImageData imagedata = BufferedImageHelper.bufferedImageToImageData(binatryBuf);

其中的imagedata是个model类,宽,高,和图像的bitset。

public class ImageData {
    private BitSet bitSet;
    private int width;
    private int height;

    public ImageData(BitSet bitSet, int width, int height) {
        this.bitSet = bitSet;
        this.width = width;
        this.height = height;
    }

    public BitSet getBitSet() {
        return bitSet;
    }

    public void setBitSet(BitSet bitSet) {
        this.bitSet = bitSet;
    }

    public int getWidth() {
        return width;
    }

    public void setWidth(int width) {
        this.width = width;
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }
}

其中的GetImage.toBufferedImage(image)

public static BufferedImage toBufferedImage(Image image) {
        if (image instanceof BufferedImage) {
            return (BufferedImage)image;
         }

         image = new Imag
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值