毕业这么久了,最近闲来准备把毕设过程中的代码整理公开一下,所有代码其实都是网上找的,但都是经过调试能跑通的,希望对需要的人有用。
PS:里边很多注释不讲什么意思了,能看懂的自然能看懂。
clc;
clear all;
%因为我毕设论文对比是8张图,所以这个画图代码就是读八张图哈。
rootdir='C:\Users\Mus\Desktop\几种典型图像';
global mnum;
mnum =zeros(8,256);
lineLength = 8; % 设置曲线数量
c = colormap(lines(lineLength )); % 为了在一个图中绘制多条曲线
x=0:1:255;
subdir=dir(rootdir);
for i=1:length(subdir)
subdirpath=fullfile(rootdir,subdir(i).name,'*.png');
images=dir(subdirpath);
for j=1:length(images)
ImageName=fullfile(rootdir,subdir(i).name,images(j).name);
ImageData=imread(ImageName);
%图像预处理
%图像大小尺寸改变
ImageData_S=imresize(ImageData,[256,256]);%调整大小到长宽256
% saveddir='C:\Users\Mus\Desktop\几种典型图像\';
% savedname=fullfile(saveddir,images(j).name);
% imwrite(ImageData_S,savedname);
% figure(1);subplot(2,4,j);imshow(ImageData_S);sgtitle("原图像");
% figure(2);subplot(2,4,j);imhist(ImageData_S);sgtitle("RGB颜色空间分量直方图");
% R=ImageData_S(:,:,1);
% G=ImageData_S(:,:,2);
% B=ImageData_S(:,:,3);
% histogramR=imhist(R);
% histogramG=imhist(G);
% histogramB=imhist(B);
% % figure(3);subplot(2,4,j);imshow(R);sgtitle('不同路面R分量');hold on;
% % figure(4);subplot(2,4,j);imshow(G);sgtitle('不同路面G分量');hold on;
% % figure(5);subplot(2,4,j);imshow(B);sgtitle('不同路面B分量');hold on;
% figure(3);plot(x,histogramR,'color',c(j,:), 'LineWidth', 0.9);xlim([0 255]);title('不同路面R分量直方图');xlabel('灰度值');ylabel('次数');hold on;
% legend('沥青干路面','沥青湿路面','积水路面','雨雪路面','泥泞雪路面','压实雪路面','冰雪路面','冰路面');
% figure(4);plot(x,histogramG,'color',c(j,:), 'LineWidth', 0.9);xlim([0 255]);title('不同路面G分量直方图');xlabel('灰度值');ylabel('次数');hold on;
% legend('沥青干路面','沥青湿路面','积水路面','雨雪路面','泥泞雪路面','压实雪路面','冰雪路面','冰路面');
% figure(5);plot(x,histogramB,'color',c(j,:), 'LineWidth', 0.9);xlim([0 255]);title('不同路面B分量直方图');xlabel('灰度值');ylabel('次数');hold on;
% legend('沥青干路面','沥青湿路面','积水路面','雨雪路面','泥泞雪路面','压实雪路面','冰雪路面','冰路面');
% figure(6);subplot(2,4,j);imhist(R);sgtitle('不同路面R分量直方图');hold on;
% figure(7);subplot(2,4,j);imhist(G);sgtitle('不同路面G分量直方图');hold on;
% figure(8);subplot(2,4,j);imhist(B);sgtitle('不同路面B分量直方图');hold on;
%图像亮度变化
% ImageData_s = imadjust(ImageData_S,[0.5 0.75],[0 1],2);
%图像平滑处理
% gausFilter = fspecial('gaussian',[5,5],1); %matlab 自带高斯模板滤波
% ImageData_P=imfilter(ImageData_S,gausFilter,'conv');
%高斯+USM进行锐化处理
ImageData_P=image_guasusm(ImageData_S);
figure(3);subplot(2,4,j);imshow(ImageData_P);sgtitle("锐化处理后的图像");
% saveddir='C:\Users\Mus\Desktop\锐化后的图像\';
% savedname=fullfile(saveddir,images(j).name);
% imwrite(ImageData_P,savedname);
% % 转HSV
% ImageData_H=rgb2hsv(ImageData_P);
% H=ImageData_H(:,:,1);
% S=ImageData_H(:,:,2);
% V=ImageData_H(:,:,3);
% histogramH=imhist(H);
% histogramS=imhist(S);
% histogramV=imhist(V);
% figure(6);plot(x,histogramH,'color',c(j,:), 'LineWidth', 0.9);xlim([0 255]);title('不同路面H分量直方图');xlabel('灰度值');ylabel('次数');hold on;
% legend('沥青干路面','沥青湿路面','积水路面','雨雪路面','泥泞雪路面','压实雪路面','冰雪路面','冰路面');
% figure(7);plot(x,histogramS,'color',c(j,:), 'LineWidth', 0.9);xlim([0 255]);title('不同路面S分量直方图');xlabel('灰度值');ylabel('次数');hold on;
% legend('沥青干路面','沥青湿路面','积水路面','雨雪路面','泥泞雪路面','压实雪路面','冰雪路面','冰路面');
% figure(8);plot(x,histogramV,'color',c(j,:), 'LineWidth', 0.9);xlim([0 255]);title('不同路面V分量直方图');xlabel('灰度值');ylabel('次数');hold on;
% legend('沥青干路面','沥青湿路面','积水路面','雨雪路面','泥泞雪路面','压实雪路面','冰雪路面','冰路面');
% figure(7);subplot(2,4,j);imshow(H);sgtitle('不同路面H分量');hold on;
% figure(8);subplot(2,4,j);imshow(S);sgtitle('不同路面S分量');hold on;
% figure(9);subplot(2,4,j);imshow(V);sgtitle('不同路面V分量');hold on;
%
% figure(10);subplot(2,4,j);imhist(H);sgtitle('不同路面H分量直方图');hold on;
% figure(11);subplot(2,4,j);imhist(S);sgtitle('不同路面S分量直方图');hold on;
% figure(12);subplot(2,4,j);imhist(V);sgtitle('不同路面V分量直方图');hold on;
% 提取图像颜色特征并绘制HSV颜色空间分量直方图
%
% ImageData_H=hsv_hist(ImageData_h);
%
% figure(4);subplot(2,4,j);plot(ImageData_H);sgtitle("HSV颜色空间分量直方图");
% 提取亮度
ImageData_L=ImageData_H(:,:,3);
%进行直方图均衡化处理
ImageData_Hist =imagedata_hist(ImageData_L);
figure(5);subplot(2,4,j);imshow(ImageData_Hist);sgtitle("直方图均衡化处理");
% %图像进行锐化处理
% % w = fspecial('laplacian', 0.8);%生成拉普拉斯滤波器
% w = fspecial('log', [5,5], 0.4);%生成高斯-拉普拉斯滤波器
% ImageData_R =imagedata_r(ImageData_Hist, w, 5);
ImageData_Hist(:,:,3) = ImageData_Hist ;
ImageData_After1= hsv2rgb(ImageData_Hist);
ImageData_After=rgb2gray(ImageData_After1);
%
% %显示处理后的图像
% figure(6);subplot(2,4,j);imshow(ImageData_After);sgtitle("处理后的图像");
% trainFeatures =Extract_GLCM_Features(ImageData_After);
H2= lbptest(ImageData_After);
H2=imhist(H2); figure(4);
% plot(x,H2,'color',c(j,:), 'LineWidth', 0.9);xlim([0 100]);title('ULBP灰度直方图');xlabel('灰度值');ylabel('灰度像素数');hold on;
% legend('沥青干路面','沥青湿路面','积水路面','雨雪路面','泥泞雪路面','压实雪路面','冰雪路面','冰路面');
% figure
% subplot(2,2,1),imshow(ImageData_S);
% title('原始图像');
% subplot(2,2,3),imshow(ImageData_After);
% title('均衡化后的图像');
% subplot(2,2,2),imhist(ImageData_S);
% title('原始图像的直方图');
% subplot(2,2,4),imhist(ImageData_After);
% title('均衡化后的图像的直方图');
% saveddir='C:\Users\Mus\Desktop\新建文件夹3';
% savedname=fullfile(saveddir,images(j).name);
% imwrite(ImageData_P,savedname);
end
end
%这个程序仅限论文需要做画图作用哈。
**高斯+USM子函数:**
function gaususm_image= image_guasusm(img)
% 分别读取RGB
image_r=img(:,:,1);
image_g=img(:,:,2);
image_b=img(:,:,3);
% 测试RGB输出
% figure;
% subplot(2,2,1),imshow(image_r),title('Red component');
% subplot(2,2,2),imshow(image_g),title('green component');
% subplot(2,2,3),imshow(image_b),title('blue component');
% subplot(2,2,4),imshow(img),title('original image');
% img= floor(img.*255);
[m,n]=size(img);
img_r=double(image_r);img_g=double(image_g);img_b=double(image_b);
sigma=0.5;lamda=20;
gausFilter=round(fspecial('gaussian',[3,3],sigma)*1024);
Mod_r=round(imfilter(img_r,gausFilter,'replicate')/1024);
Mod_r=img_r-Mod_r;
img2_r=(img_r+lamda*Mod_r);
gausFilter=round(fspecial('gaussian',[3,3],sigma)*1024);
Mod_g=round(imfilter(img_g,gausFilter,'replicate')/1024);
Mod_g=img_g-Mod_g;
img2_g=(img_g+lamda*Mod_g);
gausFilter=round(fspecial('gaussian',[3,3],sigma)*1024);
Mod_b=round(imfilter(img_b,gausFilter,'replicate')/1024);
Mod_b=img_b-Mod_b;
img2_b=(img_b+lamda*Mod_b);
% figure;
% subplot(131);imshow(uint8(img2_r));
% subplot(132);imshow(uint8(img2_g));
% subplot(133);imshow(uint8(img2_b));
rgb(:,:,1)=img2_r;
rgb(:,:,2)=img2_g;
rgb(:,:,3)=img2_b;
gaususm_image=uint8(rgb);
% gaususm_image=rgb./255;
% imwrite(uint8(rgb),'D:\Mexercise\图像批处理\测试程序USM\2.png');
% figure;imshow(uint8(rgb));
end
**转HSV空间分量子函数:**
% RGB=imread('greens.jpg'); %将图像格式文件读入为MATLAB图像对象数组数据;
% 16*4*4, 这样提取出来的HSV特征是256维的;
%h是色调,即所处的光谱颜色的位置,取值范围为0-360。该参数用角度量来表示,红(0º)、绿(120º)、蓝(240º)分别相隔120º。互补色分别相差180º。
%s是饱和度(纯度),为一比例值,范围从0到1。它表示成所选颜色的纯度和该颜色最大的纯度之间的比率。S=0时,只有灰度;S=1时为纯色。
%V是色彩的明亮程度,范围从0到1。有一点要注意:它和亮度之间并没有直接的联系。
function [m]=hsv_hist(RGB)
[M,N,~] = size(RGB);
[h,s,v] = rgb2hsv(RGB);
H = h; S = s; V = v;
h = h*360; %转换为HSV格式后h的值变为0-1,所以要乘以360来进行量化
%H量化为16级 S量化为4级 V量化为4级
for i = 1:M
for j = 1:N
if h(i,j)<=15||h(i,j)>345
H(i,j) = 0;
end
if h(i,j)<=25&&h(i,j)>15
H(i,j) = 1;
end
if h(i,j)<=45&&h(i,j)>25
H(i,j) = 2;
end
if h(i,j)<=55&&h(i,j)>45
H(i,j) = 3;
end
if h(i,j)<=80&&h(i,j)>55
H(i,j) = 4;
end
if h(i,j)<=108&&h(i,j)>80
H(i,j) = 5;
end
if h(i,j)<=140&&h(i,j)>108
H(i,j) = 6;
end
if h(i,j)<=165&&h(i,j)>140
H(i,j) = 7;
end
if h(i,j)<=190&&h(i,j)>165
H(i,j) = 8;
end
if h(i,j)<=220&&h(i,j)>190
H(i,j) = 9;
end
if h(i,j)<=255&&h(i,j)>220
H(i,j) = 10;
end
if h(i,j)<=275&&h(i,j)>255
H(i,j) = 11;
end
if h(i,j)<=290&&h(i,j)>275
H(i,j) = 12;
end
if h(i,j)<=316&&h(i,j)>290
H(i,j) = 13;
end
if h(i,j)<=330&&h(i,j)>316
H(i,j) = 14;
end
if h(i,j)<=345&&h(i,j)>330
H(i,j) = 15;
end
end
end
for i = 1:M
for j = 1:N
if s(i,j)<=0.15&&s(i,j)>0
S(i,j) = 0;
end
if s(i,j)<=0.4&&s(i,j)>0.15
S(i,j) = 1;
end
if s(i,j)<=0.75&&s(i,j)>0.4
S(i,j) = 2;
end
if s(i,j)<=1&&s(i,j)>0.75
S(i,j) = 3;
end
end
end
for i = 1:M
for j = 1:N
if v(i,j)<=0.15&&v(i,j)>0
V(i,j) = 0;
end
if v(i,j)<=0.4&&v(i,j)>0.15
V(i,j) = 1;
end
if v(i,j)<=0.75&&v(i,j)>0.4
V(i,j) = 2;
end
if v(i,j)<=1&&v(i,j)>0.75
V(i,j) = 3;
end
end
end
for i = 1:M
for j = 1:N
L(i,j) = H(i,j)*16+S(i,j)*4+V(i,j); %归一化
end
end
for i = 0:255
HSVHist(i+1) = size(find(L==i),1);
end
m=HSVHist/sum(HSVHist);
end
**直方图均衡化子函数:**
function hist_img = imagedata_hist(I)
I = floor(I.*255);
[M, N] = size(I);
size_img = M*N;
c = zeros(1,256);%统计每个每个像素值的个数
b= c;%转化前后的对照表
temp = I(:);
temp = sort(temp);
for i = 1:size_img
c(temp(i)+1) = c(temp(i)+1)+1;
end
a = c;%求和
for i = 2:256
a(i) = c(i) + a(i-1);
end
min_cdf = 10000;
for i = 1:256
if a(i)>0
if a(i) < min_cdf
min_cdf = a(i);
end
end
end
for j = 1:256
if a(j) > 0
b(j) = round(255*(a(j)-min_cdf)/(size_img-min_cdf));
end
end
for i = 1:M
for j = 1:N
I(i,j) = b(I(i,j)+1);
end
end
hist_img = I./255;
end
文章浏览阅读4.8k次。Extjs多个tab页面——panel层叠_extjs写一个panel,多个ta
文章浏览阅读1.9w次,点赞21次,收藏110次。搭建流媒体服务,将rtsp或者rtmp视频流转换为H5可以直接播放的视频。用在直播、安防监控、视频点播、屏幕画面转播等_rtmp拉流地址
文章浏览阅读292次。布置宴席最微妙的事情,就是给前来参宴的各位宾客安排座位。无论如何,总不能把两个死对头排到同一张宴会桌旁!这个艰巨任务现在就交给你,对任何一对客人,请编写程序告诉主人他们是否能被安排同席。输入格式:输入第一行给出3个正整数:N(&lt;= 100),即前来参宴的宾客总人数,则这些人从1到N编号;M为已知两两宾客之间的关系数;K为查询的条数。随后M行,每行给出一对宾客之间的关系,格式为:“宾客..._hive排座位
文章浏览阅读1.5k次。StringTokenizer類的nextToken()方法用於從此StringTokenizer依次返回下一個標記。用法:public String nextToken()參數:該方法不帶任何參數。返回值:該方法返回字符串令牌化程序行中存在的下一個令牌。下麵的程序說明StringTokenizer的nextToken()方法的用法:示例1:// Java code to illustrate n..._next token的用法
文章浏览阅读268次。网上一些校正系统时间的方法,大多需要手动操作,有没有什么工具可以自动完成相关的操作呢? 可以试试NetTime工具(http://www.timesynctool.com/).安装该工具时会创建一个自启动服务,以后每次启动系统,它都会随之启动并自动校正系统时间。_timesync 自动
文章浏览阅读2.3k次。即使我们使用了类似 *{margin: 0;padding: 0;} 这样的代码重置了浏览器默认样式,也会发现类似标签这种inline-block元素,它们之间也还存在着间距。demo:默认情况123456789101112131415_css处理手机自动留白安全距离
文章浏览阅读614次。【代码】ZZULIOJ1061: 顺序输出各位数字。_zznuoj1061顺序输出各位数字
文章浏览阅读601次。问题截图:解决方案:在pom.xml文件中添加: <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>2.4.3</version> _failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.3.0
文章浏览阅读310次。之前在[ArduPilot飞控之FAILSAFE机制](https://blog.csdn.net/lida2003/article/details/132191018)中,针对Ardupilot的`FAILSAFE`机制进行了相对完整的介绍。本章节将从代码的角度来看`FAILSAFE`代码触发入口,以及对应的应对策略。_开源飞控解锁
文章浏览阅读3.3k次。软件项目的生命周期分为六个阶段:项目前期、项目启动、项目蓝图、项目实施、项目验收、项目运维。其中项目运维是项目中的重要环节。针对本次客户反馈工作进行反思总结。_运维工作汇报不足
文章浏览阅读1.1k次。目录1.日志介绍1.1 什么是日志1.2 Linux系统使用的两种系统日志服务1.3 ELK2.rsyslog的管理2.1 系统日志术语1.2 实验1.日志介绍1.1 什么是日志网络设备、系统及服务程序等,在运作时都会产生一个叫log的事件记录;每一行日志都记载着日期、时间、使用者及动作等相关操作的描述日志记录的内容包括: 历史事件:时间,地点,人物,事件 日志级别:事件的关键性程度,Loglevel 1.2 Linux系统使用的两种系统日_linux系统日志服务
文章浏览阅读3.2k次。Arch Linux 搭建 arm64/AArch64 交叉编译环境0. 系统环境系统:Arch Linux: 成文时间最新工具版本:Binutils:2.34-1GCC:9.2.1+20200130-2GNUMake:4.31. 编译交叉编译工具链此部分参考博客.交叉编译工具链需要用到至少七个工具(库):Binutilshttps://www.gnu.org/software/binutils/..._linux编译arm64的库