毕业这么久了,最近闲来准备把毕设过程中的代码整理公开一下,所有代码其实都是网上找的,但都是经过调试能跑通的,希望对需要的人有用。
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
文章浏览阅读451次。dev/mem: 物理内存的全镜像。可以用来访问物理内存。/dev/kmem: kernel看到的虚拟内存的全镜像。可以用来访问kernel的内容。调试嵌入式Linux内核时,可能需要查看某个内核变量的值。/dev/kmem正好提供了访问内核虚拟内存的途径。现在的内核大都默认禁用了/dev/kmem,打开的方法是在 make menuconfig中选中 device drivers --> ..._dev/mem 源码实现
文章浏览阅读7.1k次,点赞2次,收藏19次。vxe-table,一个小众但功能齐全并支持excel操作的vue表格组件_vxe-table
文章浏览阅读62次。参考:http://www.ruanyifeng.com/blog/2016/01/babel.htmlBabelBabel是一个广泛使用的转码器,可以将ES6代码转为ES5代码,从而在现有环境执行// 转码前input.map(item => item + 1);// 转码后input.map(function (item) { return item..._让开发环境支持bable
文章浏览阅读2.8k次,点赞6次,收藏29次。摘要:FPGA视频处理FIFO的典型应用,视频输入FIFO的作用,视频输出FIFO的作用,视频数据跨时钟域FIFO,视频缩放FIFO的作用_fpga 频分复用 视频
文章浏览阅读575次。【代码】R语言:设置工作路径为当前文件存储路径。_r语言设置工作目录到目标文件夹
文章浏览阅读452次。格式:background: linear-gradient(direction, color-stop1, color-stop2, ...);<linear-gradient> = linear-gradient([ [ <angle> | to <side-or-corner>] ,]? &l..._background线性渐变
文章浏览阅读1k次,点赞26次,收藏8次。第十三届蓝桥杯青少年组python编程省赛真题一、题目要求(注:input()输入函数的括号中不允许添加任何信息)1、编程实现给定一个正整数N,输出正整数N中各数位最大的那个数字。例如:N=132,则输出3。2、输入输出输入描述:只有一行,输入一个正整数N输出描述:只有一行,输出正整数N中各数位最大的那个数字输入样例:
文章浏览阅读2.2k次。一个网络协议主要由以下三个要素组成:1.语法数据与控制信息的结构或格式,包括数据的组织方式、编码方式、信号电平的表示方式等。2.语义即需要发出何种控制信息,完成何种动作,以及做出何种应答,以实现数据交换的协调和差错处理。3.时序即事件实现顺序的详细说明,以实现速率匹配和排序。不完整理解:语法表示长什么样,语义表示能干什么,时序表示排序。转载于:https://blog.51cto.com/98..._网络协议三要素csdn
文章浏览阅读153次。主要的思想,将所有的系统都可以看作两部分,真正的数据log系统和各种各样的query engine所有的一致性由log系统来保证,其他各种query engine不需要考虑一致性,安全性,只需要不停的从log系统来同步数据,如果数据丢失或crash可以从log系统replay来恢复可以看出kafka系统在linkedin中的重要地位,不光是d..._the log: what every software engineer should know about real-time data's uni
文章浏览阅读746次。伟大是熬出来的 目录 前言 引言 时间熬成伟大:领导者要像狼一样坚忍 第一章 内圣外王——领导者的心态修炼 1. 天纵英才的自信心 2. 上天揽月的企图心 3. 誓不回头的决心 4. 宠辱不惊的平常心 5. 换位思考的同理心 6. 激情四射的热心 第二章 日清日高——领导者的高效能修炼 7. 积极主动,想到做到 8. 合理掌控自己的时间和生命 9. 制定目标,马..._当狼拖着受伤的右腿逃生时,右腿会成为前进的阻碍,它会毫不犹豫撕咬断自己的腿, 以
文章浏览阅读285次。在当今的大数据时代,人们对高速度和高带宽的需求越来越大,迫切希望有一种新型产品来作为高性能计算和数据中心的主要传输媒质,所以有源光缆(AOC)在这种环境下诞生了。有源光缆究竟是什么呢?应用在哪些领域,有什么优势呢?易天将为您解答!有源光缆(Active Optical Cables,简称AOC)是两端装有光收发器件的光纤线缆,主要构成部件分为光路和电路两部分。作为一种高性能计..._aoc 光缆
文章浏览阅读2.2k次。在“桌面”上按快捷键“Ctrl+R”,调出“运行”窗口。接着,在“打开”后的输入框中输入“Gpedit.msc”。并按“确定”按钮。如下图 找到“用户配置”下的“Windows设置”下的“Internet Explorer 维护”的“连接”,双击选择“自动浏览器配置”。如下图 选择“自动启动配置”,并在下面的“自动代理URL”中填写相应的PAC文件地址。如下..._設置proxy腳本