当前位置:网站首页>Matlab底层源码实现图像动态二值化
Matlab底层源码实现图像动态二值化
2022-07-15 10:15:00 【手写不期而遇】
理论
通常情况下,为了算法的稳定性,图像处理算法需要具有自适应调节阈值并进一步阈值分割,这里给出一种图像动态二值化的图像预处理算法,并在最后给出图像处理的效果。
Matlab源代码
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%动态二值化
%Author:Zhu
%时间:2022.6
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc;
image = imread("E:\\1.jpg");
image_matrix=image(:,:,1);
image_matrix=double(image_matrix);
[height,width,channels]=size(image);
%迭代阈值
threshold1 = 127;
threshold2 = 0;
%临时变量
temp1=0;
temp2=0;
temp3=0;
temp4=0;
%直方图统计
gray_map = zeros(1,256);
for i=1:height
for j=1:width
T = image_matrix(i,j)+1;
%灰度统计计数
gray_map(T)=gray_map(T)+1;
end
end
while(1)
%计算下一个迭代阈值
for i=1:threshold1
temp1=temp1+gray_map(i)*i;
temp2=temp2+gray_map(i);
end
for i=threshold1:256
temp3=temp1+gray_map(i)*i;
temp4=temp2+gray_map(i);
end
threshold2 =(temp1/temp2+temp3/temp4)/2;
threshold2=ceil(threshold2);
%看迭代结果是否收敛
if(threshold1==threshold2)
threshold1=ceil(threshold1);
break;
else
threshold1 = threshold2;
end
end
%对各像素进行灰度转换
for i =1:height
for j=1:width
currentPixel = image_matrix(i,j);
if(currentPixel<threshold1)
currentPixel = 0;
else
currentPixel = 255;
end
image_matrix(i,j)=currentPixel;
end
end
%显示图
image_out = uint8(image_matrix);
subplot(1,2,1);
imshow(image);
subplot(1,2,2);
imshow(image_out);
实现效果

边栏推荐
- Realization of greedy snake in C language
- Sidecar traffic management and multi protocol sniffing in service grid
- Special topic of software R & D efficiency demand value stream analysis
- Oracle P8 architect resigned and angrily criticized MySQL as a "bad database"
- 从0开始的 TypeScriptの十四:内置工具类型
- Introduction and basic use of container image construction tool kaniko (googlecontainertools/kaniko)
- 基于机器学习的笑脸检测
- 034. Code rollback reset current branch to here
- 2021年山东省职业院校技能大赛 中职组“网络搭建与应用”赛项 (正式赛题)
- QT | VS2017 + Qt5.14.2环境搭建
猜你喜欢
![[source code] implementation principle of HashSet](/img/6e/4cc6e4fffd0d6802a8338286a558d5.png)
[source code] implementation principle of HashSet

有证书有目录!|海泰密码服务平台

北航学长的NLP赛事教程!

Matlab底层源代码实现Halcon scale_image_range(可用于背景分割)

Analysis of technical design details dynamically displayed or hidden by SAP Fiori application adapt UI

Q4 resource file

Q3 qmainwindow status bar riveted parts core parts

对接企业微信,客户关系管理也可以很简单!

Neuron and metahunan drive whole body steps in real time

Prometheus operator deployment
随机推荐
Threejs personal notes
Interesting and informative. A cognitive upgrade of zero trust network security architecture
Important - Im open source project openim about version management and v2.3.0 release plan
基于机器学习的笑脸检测
hi各位大佬,想请教一下mysql-cdc这里的startupOptions 为什么只支持initi
Talking about some features of improving work efficiency supported by slack channel
小程序webview页面转发后,打开页面空白
Pytoch (II) -- main components of pytorch
Technical implementation details of SAP e-commerce cloud Spartacus UI sitecontextrouteshandler
[leetcode] day100 color classification
Q3 qmainwindow menu bar and toolbar
Luogu daily three questions -- the next day
Matlab底层源代码实现Halcon scale_image_max算子效果
[kapok] Summer Challenge # Hongmeng small game project Sudoku
各位大佬,oraclecdc 总是报这个错,请问知道是怎么回事吗?
A top-notch book and an ingenious translation! Machine learning and asset pricing is heavily listed
What is website ICP filing?
[source code] implementation principle of HashSet
Q3 qmainwindow status bar riveted parts core parts
002 descendant selector