图像处理之图像分割

  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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值