毕业这么久了,最近闲来准备把毕设过程中的代码整理公开一下,所有代码其实都是网上找的,但都是经过调试能跑通的,希望对需要的人有用。
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
文章浏览阅读2.1k次,点赞101次,收藏78次。【学习背景】今天主要是来了解Java线程Thread中的run()、start()两个方法的执行有哪些区别,会给出一个简单的测试代码样例,快速理解两者的区别,再从源码层面去追溯start()底层是如何最终调用Thread#run()方法的,个人觉得这样的学习不论对面试,还是实际编程来说都是比较有帮助的。进入正文~学习目录一、代码测试二、源码分析2.1 run()方法2.2 start()方法三、使用总结一、代码测试执行Thread的run()、start()方法的测试代码如下:public_jdk的源码hotspot跟jdk是分开的
文章浏览阅读4.4k次,点赞90次,收藏85次。俄乌冲突中,各方势力通过数据擦除恶意软件破坏关键信息基础设施计算机的数据,达到深度致瘫的效果,同时窃取重要敏感信息。_俄乌网络战观察(一)
文章浏览阅读1.7w次,点赞23次,收藏139次。Maven 私服是一种特殊的Maven远程仓库,它是架设在局域网内的仓库服务,用来代理位于外部的远程仓库(中央仓库、其他远程公共仓库)。当然也并不是说私服只能建立在局域网,也有很多公司会直接把私服部署到公网,具体还是得看公司业务的性质是否是保密的等等,因为局域网的话只能在公司用,部署到公网的话员工在家里也可以办公使用。_nexus maven
文章浏览阅读934次。我先用所有的样本数据对模型做几轮初步训练,让深度神经模型基本拟合(数万条记录的训练集,识别率到99%左右),具备初步的识别能力,这时的模型就是“直男”。相较于训练很多轮、拟合程度很高的“油腻男”,它的拟合程度较低,还是“直男愣头青”。..............._java ocr ai识别训练
文章浏览阅读688次。一、问题现象: 在数据库表中日期字段中存的日期光有年月日,没有时分秒。二、产生原因:三 解决办法 检查表的相应映射xml文件。 <property name="operateDate" type="Date">如果同上面所写,那问题出在 type类型上了正确写法 :<property name="operateDate" type="java.util..._hibernate解析時間只有年月日沒有時分秒
文章浏览阅读1k次。通过react-native-tab-navigator实现下面这样的底部Tab切换安装npm install react-native-tab-navigator --save属性TabNavigator 属性 属性名 描述 sceneStyle 切换的每一屏的样式,等同于每一屏根View的样式 tabBarStyle ..._evaluating react-native-tab-navigator.js
文章浏览阅读6.4k次,点赞6次,收藏36次。1、redux中间件中间件提供第三方插件的模式,自定义拦截 action -> reducer 的过程。变为 action -> middlewares -> reducer 。这种机制可以让我们改变数据流,实现如异步 action ,action 过滤,日志输出,异常报告等功能。常见的中间件:redux-logger:提供日志输出redux-thunk:处理异步操作..._recate面试
文章浏览阅读405次。由于要在开发板中加载libjpeg,不能使用gcc编译的库文件给以使用,需要自己配置使用另外的编译器编译该库文件。/usr/bin/ld:.libs/jaricom.o:RelocationsingenericELF(EM:40)/usr/bin/ld:.libs/jaricom.o:RelocationsingenericELF(EM:40)...._jpeg_utils.lo: relocations in generic elf (em: 8) error adding symbols: file
文章浏览阅读578次,点赞10次,收藏17次。【办公类-22-06】周计划系列(1)“信息窗” (2024年调整版本)
文章浏览阅读309次。SEO全称为Search Engine Optimization,中文解释为搜索引擎优化。一般指通过对网站内部调整优化及站外优化,使网站满足搜索引擎收录排名需求,在搜索引擎中提高关键词排名,从而把精准..._百度seo resetful
文章浏览阅读438次。回归预测 | Matlab实现HPO-ELM猎食者算法优化极限学习机的数据回归预测_猎食者优化算法
文章浏览阅读55次。近日,苹果向所有开发者推送警告邮件,宣布未来将禁用 APP 内部的“动态分发”功能。并要求开发者在自家 APP 中删除 JSPatch 相关框架,否则 APP 将面临下架或禁止上架。截止发稿,已有部分开发者新递交的APP受此影响被苹果审核部门拒绝。这一动作,宣告着 APP Store 为“热更新”判了“死刑”,未来应用更新则将进入“原生”时代,用户需..._ios对开发者应用更新频次有限制吗