1. 图像阈值分割之图像二值化处理

        阈值化分割的基本思想:设定阈值T,已知图像坐标(x,y)处的像素值为i(x,y)。如果i(x,y)>T,则i(x,y)=255,如果i(x,y)<=T,则i(x,y)=0。

#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include "cv.h"
#include "highgui.h"
int main(){
	    Mat Images = (cv::Mat_<uchar>(3,3)<<1,1,1,128,128,128,200,200,255);
	    int Threshold_value = 128;
	    (Images.setTo(255,Images > Threshold_value)).setTo(0,Images <= Threshold_value);
            return 0;
   }

 

       逆取值阈值化分割的基本思想:设定阈值T,已知图像坐标(x,y)处的像素值为i(x,y)。如果i(x,y)>T,则i(x,y)=0,如果i(x,y)<=T,则i(x,y)=255。  

#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include "cv.h"
#include "highgui.h"
int main(){
	    Mat Images = (cv::Mat_<uchar>(3,3)<<1,1,1,128,128,128,200,200,255);
	    int Threshold_value = 128;
            (Images.setTo(255,Images > Threshold_value)).setTo(0,Images <= Threshold_value);
            Images = ~Images;
            return 0;
   }    

 

       截断阈值化分割的基本思想:设定阈值T,已知图像坐标(x,y)处的像素值为i(x,y)。如果i(x,y)>T,则i(x,y)=T,如果i(x,y)<=T,则i(x,y)的值不变。

#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include "cv.h"
#include "highgui.h"
int main(){
	    Mat Images = (cv::Mat_<uchar>(3,3)<<1,1,1,128,128,128,200,200,255);
	    int Threshold_value = 128;
            Images.setTo(Threshold_value,Images > Threshold_value);
            return 0;
   }

 

       置零阈值化分割的基本思想:设定阈值T,已知图像坐标(x,y)处的像素值为i(x,y)。如果i(x,y)>T,则i(x,y)的值不变,如果i(x,y)<=T,则i(x,y)=0。

#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include "cv.h"
#include "highgui.h"
int main(){
	    Mat Images = (cv::Mat_<uchar>(3,3)<<1,1,1,128,128,128,200,200,255);
	    int Threshold_value = 128;
            Images.setTo(0,Images <= Threshold_value);
            return 0;
   }

 

         逆取值阈值化分割的基本思想:设定阈值T,已知图像坐标(x,y)处的像素值为i(x,y)。如果i(x,y)>T,则i(x,y)=0,如果i(x,y)<=T,则i(x,y)=255。

#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include "cv.h"
#include "highgui.h"
int main(){
	    Mat Images = (cv::Mat_<uchar>(3,3)<<1,1,1,128,128,128,200,200,255);
	    int Threshold_value = 128;
            Images.setTo(0,Images > Threshold_value);
            return 0;
   }

 

作者将于知乎同时更新文章,如有明显错误望各位指导更正,知乎连接: https://zhuanlan.zhihu.com/p/152482795

Logo

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。

更多推荐