-
Notifications
You must be signed in to change notification settings - Fork 0
/
hog_kmeans.m
48 lines (46 loc) · 1.96 KB
/
hog_kmeans.m
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
39
40
41
42
43
44
45
46
47
48
file_path = 'D:\黄梓萌\智能物联网\test-codes\cleanv3\';% 图像文件夹路径
img_path_list = dir(strcat(file_path,'*.jpg'));%获取该文件夹中所有bmp格式的图像
img_num = length(img_path_list);%获取图像总数量
% I=cell(1,img_num);
% max_h = 317;
% max_w = 702;
% I = zeros(img_num,max_w,max_h,3);
feature_num = 117648;
I = zeros(img_num,feature_num);
mkdir('hog_virtual');
if img_num > 0 %有满足条件的图像
for j = 1:img_num %逐一读取图像
image_name = img_path_list(j).name;% 图像名
image =imread(strcat(file_path,image_name));
[featureVector,hogVisualization] = extractHOGFeatures(image);
I(j,:) = featureVector;
fprintf('%d %s\n',j,strcat(file_path,image_name));% 显示正在处理的图像名
hog_save_path = sprintf('hog_virtual/%s',image_name);
f = figure(1);
imshow(image);
hold on;
plot(hogVisualization);
% imwrite(hogVisualization,hog_save_path);
pause(999999999);
saveas(f,hog_save_path);
close(f);
%图像处理过程 省略
%这里直接可以访问细胞元数据的方式访问数据
end
end
% I = reshape(I,img_num,max_w*max_h*3);
[idx,C] = kmeans(I,9);
% file_path_origin = 'D:\黄梓萌\智能物联网\test-codes\test2\test\';% 图像文件夹路径
% img_path_list_origin = dir(strcat(file_path_origin,'*.jpg'));%获取该文件夹中所有bmp格式的图像
% mkdir('resultv6_9');
% for i = 1:img_num
% cur_idx = idx(i,1);
% % image_name = img_path_list_origin(i).name;% 图像名
% image_name = img_path_list(i).name;% 图像名
% image =imread(strcat(file_path_origin,image_name));
% dir_path = sprintf('resultv6_9/%d/',cur_idx);
% mkdir(dir_path);
% cur_path = sprintf('resultv6_9/%d/%s',cur_idx,image_name);
% fprintf('%d %s\n',j,strcat(file_path_origin,image_name));% 显示正在处理的图像名
% imwrite(image,cur_path);
% end