ZYNQ图像处理(4)——灰度图像转二值化图像

1、二值化图像简介

前面已经完成了摄像头图像的采集和显示,以及RGB图像转灰度图。二值化图像在图像处理领域同样有广泛的应用,本节介绍如何用FPGA实现灰度转二值化图形。灰度实现二值化的原理很简单,只需要设置一个阈值,将每个像素的灰度和阈值比较,大于阈值就输出255,小于阈值就输出0。
在这里插入图片描述

2、二值化图像matlab仿真

这边简单添加了二值化的matlab代码,代码如下图所示。

clc;
clear all;

img_rgb=imread('dog.png');

%high and width
h=size(img_rgb,1);
w=size(img_rgb,2);

%rgb dog show
subplot(231);
imshow(img_rgb);
title('rgb dog');

% Relized method 2:myself Algorithm realized
% Y = ( R*77 + G*150 + B*29) >>8
% Cb = (-R*44 - G*84 + B*128) >>8
% Cr = ( R*128 - G*108 - B*20) >>8
img_rgb=double(img_rgb);
img_y=zeros(h,w);
img_u=zeros(h,w);
img_v=zeros(h,w);
for i = 1 : h
    for j = 1 : w
        img_y(i,j) = bitshift(( img_rgb(i,j,1)*77 + img_rgb(i,j,2)*150 + img_rgb(i,j,3)*29),-8);
        img_u(i,j) = bitshift((-img_rgb(i,j,1)*44 - img_rgb(i,j,2)*84 + img_rgb(i,j,3)*128 + 32678),-8);
        img_v(i,j) = bitshift(( img_rgb(i,j,1)*128 - img_rgb(i,j,2)*108 - img_rgb(i,j,3)*20 + 32678),-8);
    end
end
img_y = uint8(img_y); 
img_u = uint8(img_u); 
img_v = uint8(img_v); 

% gray to bin
% greater then threshold:1 
% smaller than threshold:0
img_bin=zeros(h,w);
img_bin1=zeros(h,w);
THRESHOLD_DATA=80;
THRESHOLD_DATA1=120;
for i=1:h
    for j=1:w
        if(img_y(i,j)>THRESHOLD_DATA)
            img_bin(i,j)=255;
        else
            img_bin(i,j)=0;
        end
        if(img_y(i,j)>THRESHOLD_DATA1)
            img_bin1(i,j
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

树叶~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值