-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path生成图像库数据.m
More file actions
38 lines (33 loc) · 933 Bytes
/
Copy path生成图像库数据.m
File metadata and controls
38 lines (33 loc) · 933 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
clear;
for number = 0:29
filename = num2str(number);
str1 = ('E:\jpeg\');
str11 = ('E:\jpeg\data\');
str2 = ('.jpg');
str3 = ('.dat');
imgpath = strcat(str1,filename,str2);
I = imread(imgpath);
Im = rgb2gray(I);
imshow(Im); %%%读入图像并显示出来
[m,n] = size(Im); %%%获取图像尺寸
x = zeros(1,256); %%%生成一个矩阵用于后面保存像素点个数
for y = 0:255
flag = 0;
for i = 1:m
for j = 1:n
if Im(i,j) == y
flag = flag + 1;
end
end
end
x(1,y+1) = flag;
end %%%统计出每个灰度值的像素点个数,并放置到 x 矩阵中
datapath = strcat(str11,filename,str3);
fid = fopen(datapath,'wb');
fwrite(fid,x,'long');
fclose(fid); %%%储存每幅图的矩阵到一个二进制文件中
figure(1),bar(x);
title('灰度直方图');
xlabel('灰度值');
ylabel('出现次数'); %%%画直方图,只能画出最后一幅图的直方图
end