Skip to content

Commit f373fb6

Browse files
authored
Add files via upload
1 parent dc1c9b7 commit f373fb6

File tree

8 files changed

+308
-0
lines changed

8 files changed

+308
-0
lines changed

Pretreatment/Gray2RGB.m

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
%============================================
2+
% 单通道图像呈现彩图效果
3+
% 其他通道用全黑图表示
4+
%===============================================
5+
clc
6+
clearvars
7+
close all
8+
9+
tic
10+
11+
[FileName, FilePath]=uigetfile('*.jpg;*.png;*.tif;*.img;*.bmp;','请选择一幅参考图片');
12+
image_name = [FilePath FileName];
13+
14+
Iorg = imread(image_name);
15+
[rI, cI] = size(Iorg);
16+
17+
Ir = zeros(rI, cI, 3);
18+
19+
%-- 输入对话框,选择呈现颜色 --%
20+
% 1-红色; 2-绿色; 3-蓝色
21+
prompt = {'请输入呈现颜色(1红色; 2绿色; 3蓝色)'};
22+
title = '单通道图像呈现彩图效果';
23+
lines = [1]';
24+
def = {'1'};
25+
Channel_input = inputdlg(prompt, title, lines, def);
26+
Nc = str2double(Channel_input);
27+
%-----------------------------%
28+
29+
Ir(:,:,Nc) = Iorg;
30+
31+
%-- 保存图像 --%
32+
rf = [FilePath, 'RGB-', FileName];
33+
imwrite(uint8(Ir), rf);
34+
%--------------%
35+
36+
37+
38+
39+
40+
41+
42+
43+
44+
45+
46+
47+
toc

Pretreatment/Part_Divide.m

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
file_path = 'D:\MATLAB\bin\IMAGES\R_G_Enhanced\G_Channel\G_target_1024_enhanced\';% 图像文件夹路径
2+
img_path_list = dir(strcat(file_path,'*.tif'));%获取该文件夹中所有jpg格式的图像
3+
img_num = length(img_path_list);%获取图像总数量
4+
img_num_need = img_num - 8;
5+
if img_num > 0 %有满足条件的图像
6+
for k = img_num_need + 1 : img_num %逐一读取图像
7+
image_name = img_path_list(k).name;% 图像名
8+
Im= imread(strcat(file_path,image_name));
9+
10+
11+
L = size(Im);
12+
height= 128 ;
13+
width= 128 ;
14+
max_row = floor(L(1)/height);
15+
max_col = floor(L(2)/width);
16+
seg = cell(max_row,max_col);
17+
%分块
18+
for row = 1:max_row
19+
for col = 1:max_col
20+
seg(row,col)= {Im((row-1)*height+1:row*height,(col-1)*width+1:col*width,:)};
21+
end
22+
end
23+
24+
25+
for i=1:max_row*max_col
26+
imwrite(seg{i},strcat('D:\MATLAB\bin\IMAGES\R_G_Partition\G_Part\test_target_1024_128\',int2str(i),'part_',image_name));
27+
end
28+
% 画出分块的边界
29+
% for row = 1:max_row
30+
% for col = 1:max_col
31+
% rectangle('Position',[160*(col-1),160*(row-1),160,160],...
32+
% 'LineWidth',2,'LineStyle','-','EdgeColor','r');
33+
% end
34+
% end
35+
% hold off
36+
37+
38+
end
39+
end
40+

Pretreatment/RBB.m

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
file_path = 'D:/ALL_DataSet/R_G_Partition/R_Part/train_target/';% 图像文件夹路径
2+
img_path_list = dir(strcat(file_path,'*.tif'));%获取该文件夹中所有jpg格式的图像
3+
img_num = length(img_path_list);%获取图像总数量
4+
if img_num > 0 %有满足条件的图像
5+
for k = 1:img_num %逐一读取图像
6+
image_name = img_path_list(k).name;% 图像名
7+
img = imread(strcat(file_path,image_name));
8+
9+
black = imread('D:/PycharmDOC/test_photo/all_black.tif');
10+
11+
x = cat(3, img, black, black);
12+
13+
Img_R_path = strcat('D:/ALL_DataSet/RBB/train/RBB_' ,image_name);
14+
imwrite(x ,Img_R_path);
15+
end
16+
end

Pretreatment/RGB_split.m

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
file_path = 'D:/MATLAB/bin/IMAGES/Original_512/';% 图像文件夹路径
2+
img_path_list = dir(strcat(file_path,'*.tif'));%获取该文件夹中所有jpg格式的图像
3+
img_num = length(img_path_list);%获取图像总数量
4+
if img_num > 0 %有满足条件的图像
5+
for j = 1:img_num %逐一读取图像
6+
image_name = img_path_list(j).name;% 图像名
7+
Image = imread(strcat(file_path,image_name));
8+
9+
I1=Image(:,:,2);%G通道
10+
11+
12+
Img_R_path = strcat('D:/MATLAB/bin/IMAGES/G_channel/original_512/' , 'gc_512_', image_name);
13+
14+
%保存结果
15+
16+
imwrite(I1,Img_R_path);
17+
18+
end
19+
end

Pretreatment/RG_Enhance.m

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
file_path_r = 'D:/ALL_DataSet/R_G_Partition/R_Part/train_target/';% 图像文件夹路径
2+
file_path_g = 'D:/ALL_DataSet/R_G_Partition/G_Part/train_target_1024_128/';% 图像文件夹路径
3+
img_path_list_r = dir(strcat(file_path_r,'*.tif'));%获取该文件夹中所有tif格式的图像
4+
img_path_list_g = dir(strcat(file_path_g,'*.tif'));%获取该文件夹中所有tif格式的图像
5+
img_num = length(img_path_list_r);%获取图像总数量
6+
if img_num > 0 %有满足条件的图像
7+
for k = 1:img_num %逐一读取图像
8+
image_name_r = img_path_list_r(k).name;%
9+
image_name_g = img_path_list_g(k).name;% 图像名
10+
11+
imgr = imread(strcat(file_path_r,image_name_r));
12+
imgg = imread(strcat(file_path_g,image_name_g));
13+
black = imread('D:/PycharmDOC/test_photo/all_black.tif');
14+
15+
x = cat(3, imgr, imgg, imgg);
16+
17+
Img_R_path = strcat('D:/ALL_DataSet/RGGE/train/RGGE_' ,image_name_r);
18+
imwrite(x ,Img_R_path);
19+
end
20+
end

Pretreatment/ThreeCopy.m

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
file_path = 'D:/ALL_DataSet/R_G_Partition/R_Part/train_input/';% 图像文件夹路径
2+
img_path_list = dir(strcat(file_path,'*.tif'));%获取该文件夹中所有jpg格式的图像
3+
img_num = length(img_path_list);%获取图像总数量
4+
if img_num > 0 %有满足条件的图像
5+
for k = 1:img_num %逐一读取图像
6+
image_name = img_path_list(k).name;% 图像名
7+
img = imread(strcat(file_path,image_name));
8+
9+
x = repmat(img,[1,1,3]);%将单通道图片转换为三通道图片
10+
11+
Img_R_path = strcat('D:/ALL_DataSet/ThreeFoldGrayRed/train_input/TCR_' ,image_name);
12+
imwrite(x ,Img_R_path);
13+
end
14+
end

Pretreatment/lighten_lashen.m

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
file_path = 'D:/MATLAB/bin/IMAGES/R_G_SingleChannels/G_channel/original_1024/';% 图像文件夹路径
2+
img_path_list = dir(strcat(file_path,'*.tif'));%获取该文件夹中所有jpg格式的图像
3+
img_num = length(img_path_list);%获取图像总数量
4+
if img_num > 0 %有满足条件的图像
5+
for k = 1:img_num %逐一读取图像
6+
image_name = img_path_list(k).name;% 图像名
7+
Ipi = imread(strcat(file_path,image_name));
8+
9+
% figure;
10+
% subplot(2,2,1);
11+
% imshow(uint8(Ipi));title('1024红色单通道');
12+
%
13+
% original512 = imread('D:\MATLAB\bin\IMAGES\R_channel\original512\rc_512_1-512pix-speed7-ave1.tif')
14+
% subplot(2,2,2)
15+
% imshow(original512);title('512红色单通道')
16+
17+
%-- !!!!整体加亮!!!! --%
18+
CL = 54;
19+
Ipi_CL = Ipi + CL;
20+
% subplot(2,2,3);
21+
% imshow(uint8(Ipi_CL));title('整体加亮效果');
22+
%-----------------------------%
23+
24+
%-- !!!!非线性灰度拉伸!!!!--%
25+
% gamma < 1 低灰度区强拉伸,高灰度区弱拉伸甚至压缩
26+
Ipi_histequ = imadjust(Ipi_CL, [57/255, 150/255], [40/255, 255/255], 0.85);
27+
% subplot(2,2,4)
28+
% imshow(uint8(Ipi_histequ));title('非线性灰度拉伸');
29+
30+
Img_R_path = strcat('D:/MATLAB/bin/IMAGES/R_G_Enhanced/G_Channel/G_target_1024_enhanced/' ,image_name);
31+
imwrite(Ipi_histequ ,Img_R_path);
32+
end
33+
end

Pretreatment/mpmRGBimadjust.m

+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
%======================================================
2+
% MPM灰度均衡
3+
% f1=imadjust(f,[low_in high_in],[low_out high_out],gamma)
4+
%=======================================================
5+
6+
clc
7+
close all
8+
clearvars
9+
tic
10+
11+
[FileName, FilePath]=uigetfile('*.jpg;*.png;*.tif;*.img;*.bmp;','请选择一幅参考图片');
12+
image_name = [FilePath FileName];
13+
14+
Iorg = imread(image_name);
15+
[rI, cI] = size(Iorg(:,:,1));
16+
17+
%-- 判断图像信息所在的通道 --%
18+
ifocus = zeros(1,3); % 需要处理的分量,初始值为0,对应分量有值时,元素变为1 [0,0,0]
19+
for i=1:3 % i=1红色 ; i=2绿色; i=3蓝色
20+
Inidraw = Iorg(:,:,i); %通道读取
21+
Meani = mean(Inidraw(:)); %先把矩阵转化为向量,然后计算均值
22+
if(Meani>1) % 该分量有信息,理论上应该大于0就说明有信息,但是为了去噪,设成略大的值
23+
ifocus(i) = 1;
24+
end
25+
end
26+
%---------------------------%
27+
28+
[r,c,v] = find(ifocus~=0);
29+
30+
%%
31+
% 只处理有信息的分量
32+
Ir = zeros(rI, cI, 3);
33+
for i=2
34+
Ipi = Iorg(:,:,c(i));
35+
figure;
36+
subplot(2,2,1);
37+
imshow(uint8(Ipi));title('1024绿色单通道');
38+
39+
original512 = imread('D:\MATLAB\bin\IMAGES\R_G_SingleChannels\G_channel\original_512\gc_512_1-512pix-speed7-ave1.tif')
40+
subplot(2,2,2)
41+
imshow(original512);title('512绿色单通道')
42+
43+
%-- !!!!整体加亮!!!! --%
44+
CL = 54;
45+
Ipi_CL = Ipi + CL;
46+
subplot(2,2,3);
47+
imshow(uint8(Ipi_CL));title('整体加亮效果');
48+
%-----------------------------%
49+
50+
%-- !!!!非线性灰度拉伸!!!!--%
51+
% gamma < 1 低灰度区强拉伸,高灰度区弱拉伸甚至压缩
52+
Ipi_histequ = imadjust(Ipi_CL, [57/255, 150/255], [40/255, 255/255], 0.85);
53+
subplot(2,2,4)
54+
imshow(uint8(Ipi_histequ));title('非线性灰度拉伸');
55+
%---------------------------------%
56+
57+
Ir(:,:,i) = Ipi_histequ;
58+
59+
%-- 灰度直方图(原图) --%
60+
%[count_pi, x_pi] = imhist(Ipi); % xn是灰度值,count_n是出现的次数
61+
%[count_ri, x_ri] = imhist(Ir(:,:,i));
62+
%f_pi = count_pi/(rI*cI); % 出现次数归一化
63+
%f_ri = count_ri/(rI*cI);
64+
65+
figure
66+
subplot(2,2,1);
67+
% stem(x_pi, f_pi, 'b.');
68+
imhist(Ipi);
69+
title('灰度直方图-原图');
70+
71+
subplot(2,2,2);
72+
imhist(Ipi_CL);title('灰度直方图-整体加亮');
73+
74+
subplot(2,2,3);
75+
% stem(x_ri, f_ri, 'r.');
76+
imhist(uint8(Ir(:,:,i)));
77+
title('灰度直方图-均衡后');
78+
%-----------------------------%
79+
80+
%-----------------------------%
81+
figure
82+
IpiShow = zeros(rI,cI,3);
83+
IpiShow(:,:,i) = Ipi;
84+
imshow(uint8(IpiShow));title('原始RGB图');
85+
86+
figure
87+
IriShow = zeros(rI,cI,3);
88+
IriShow(:,:,i) = Ipi_histequ;
89+
imgs = uint8(IriShow);
90+
imshow(uint8(IriShow));title('增亮+非线性拉伸RGB图');
91+
%-----------------------------%
92+
93+
%-- 保存图像 --%
94+
switch i
95+
case 1
96+
ChannelName = 'R-';
97+
case 2
98+
ChannelName = 'G-';
99+
case 3
100+
ChannelName = 'B-';
101+
end
102+
103+
rfpi = [FilePath, 'org-', ChannelName, FileName];
104+
imwrite(uint8(IpiShow), rfpi);
105+
106+
rfri = [FilePath, 'Heq-', ChannelName, FileName];
107+
I1 = imgs(:,:,1);
108+
imwrite(I1, rfri);
109+
%--------------%
110+
end
111+
112+
113+
114+
115+
116+
117+
118+
119+
toc

0 commit comments

Comments
 (0)