阈值化分割的基本思想:设定阈值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