区别黑白照片和彩色照片

java区别黑白和彩色照片原理:通过读照片流,获取每个点位的色彩灰度,当灰度点数大于60个点位或者更多的时候则认定其为黑白照片。

代码如下:

	public static  boolean execote(File file){
		BufferedImage src;
		try {
			src = ImageIO.read(file);
			int height =src.getHeight();
			int width=src.getWidth();	
			//长宽 140px
			int [] rgb=new int[4];
			int o=0;
			int x;		
			if(height>140 && width>140){
				for(int i=0;i<width;i++){
					for (int j=0;j<height;j++){
						int piexl=src.getRGB(i, j);//获取像素点点数为 height*width
						rgb[1]=(piexl & 0xff0000)>>16;//抽取红色的值
						rgb[2]=(piexl & 0xff00)>>8;//抽取绿色
						rgb[3]=(piexl & 0xff);//抽取蓝色
						//获取相差最大值
						 x=	Math.max(Math.abs(rgb[1]-rgb[2]),(Math.max(Math.abs(rgb[1]-rgb[3]),Math.abs(rgb[2]-rgb[3]))));
						if(x>50){//灰度大于50  像素点数量大于60点
							o+=1;
							if(o>=60){
								return true;
							}
						}
					}
				}
			}
		} catch (Exception e) {
			src=null;
			System.out.println(file.getName());
			//e.printStackTrace();
		}finally{
		
		}
		return false;
	}

  

转载于:https://www.cnblogs.com/driftking/p/6732129.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值