图像二值化-MATLAB实现

ntfs格式分区图像值化-MATLAB实现1.图像⼆值化代码:
A=imread('hw1.chips1.GIF');  %读取到⼀张图⽚
%thresh = graythresh(A);    %⾃动确定⼆值化阈值
I2 = im2bw(A,120/255); %对图像⼆值化
figure();
subplot(1,2,1);
imshow(A);    %显⽰⼆值化之前的图⽚
title('原图');
phc管桩subplot(1,2,2);
imshow(I2);    %显⽰⼆值化之后的图⽚
title('⼆值化');
2.求⽬标和背景均值和⽅差
oriImg = imread('hw1.chips1.GIF');
grayImg = oriImg;
%grayImg = rgb2gray(oriImg); %转换为灰度图
grayImg = double(grayImg);
[m, n] = size(oriImg);
foreCount = 0;
foreTotal = 0;
backCount = 0;
backTotal = 0;
for x = 1:m
for y = 1:n
if(grayImg(x,y) >= 128)
foreCount = foreCount + 1;
foreTotal = foreTotal + grayImg(x,y);
else
backCount = backCount + 1;
backTotal = backTotal + grayImg(x,y);
end
end
end
backMean = backTotal / backCount;
foreMean = foreTotal / foreCount;
backSqu = 0;pc133
foreSqu = 0;
for x =1:m
for y = 1:n
if(grayImg(x,y) >= 128)
foreSqu = foreSqu + (grayImg(x,y) - foreMean)^2;
else
backSqu = backSqu + (grayImg(x,y) - backMean)^2;
end
end
end
backSqu = sqrt(backSqu / backTotal);
foreSqu = sqrt(foreSqu / foreTotal);
disp(strcat('背景均值', num2str(backMean)));
一江春水向东流任正非
disp(strcat('背景标准差', num2str(backSqu)));
disp(strcat('前景均值', num2str(foreMean)));
disp(strcat('前景标准差', num2str(foreSqu)));
3.求⽬标和背景⾼斯分布(双峰直⽅图)
x = 0:0.1:256;北京个别患者出现非典型症状
y1 = gaussmf(x,[backSqu^2 backMean]); plot(x, y1);
hold on;
y2 = gaussmf(x,[foreSqu^2 foreMean]); plot(x, y2);复旦求是三校生高复
title('⾼斯分布');

本文发布于:2024-09-21 22:40:59,感谢您对本站的认可!

本文链接:https://www.17tex.com/xueshu/31798.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:值化   背景   图像
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议