代码拉取完成,页面将自动刷新
%% 图片数据库转化为特征向量
clc
clear
% 本地folder 图片构建特征向量
errorDownload_file = 'D:\Program Files\MATLAB\R2018a\work\特征提取\outputData\errorDownload_file.txt';
DataSetFolder = 'D:\Program Files\MATLAB\R2018a\work\特征提取\dataset\home textiles-v1.0'; % 数据文件夹路径
% DataSetFolder = 'E:\Program Files\MATLAB\R2018a\work\特征提取\dataset\home textiles-v2.0';
DataSet_outputFolder = 'D:\Program Files\MATLAB\R2018a\work\特征提取\outputData';
DataSet_FileName = '\DataSet_FeatureVec_file.txt';
fun_ImageFileTransformDataSet(DataSetFolder, DataSet_outputFolder, DataSet_FileName, errorDownload_file);
% URLsql图片构建特征向量
errorDownload_file = 'D:\Program Files\MATLAB\R2018a\work\特征提取\outputData\errorDownload_file.txt';
DataSet_outputFolder = 'D:\Program Files\MATLAB\R2018a\work\特征提取\outputData';
DataSet_FileName = '\DataSet_FeatureVec.txt';
DataSet_savefile = [DataSet_outputFolder, DataSet_FileName];
fun_ImageUrlSqlTransformDataSet(DataSet_outputFolder, DataSet_FileName, errorDownload_file);
%% 错误图片再尝试
fun_ImageErrorTransformDataSet(errorDownload_file, DataSet_outputFolder, DataSet_FileName)
%% 得到距离和相似度的最优转化参数
queryImage = {'http://www.591wx.com/Upload/webAdv/2017-09-20/cc97c7deb84840a19f35df27eb9b5c48.jpg'};
Parameter_Dist2Similarity_best = fun_getBestParmForSimilarity(queryImage, DataSet_outputFolder, DataSet_FileName);
%% 聚类
% todo:使用tall得到聚类中心,使用mapreduce得到各个类别的样本集(非常好的构思)。
outputname = 'first';
% Cluster_outputFolder = 'D:\Program Files\MATLAB\R2018a\work\特征提取\outputData\Cluster_tall';
% fun_FeatureCluster(DataSet_outputFolder, DataSet_FileName, Cluster_outputFolder, outputname); % tall并行聚类,但是对60万数据集遍历了600次
Cluster_outputFolder = 'D:\Program Files\MATLAB\R2018a\work\特征提取\outputData\Cluster_parallel';
fun_FeatureCluster_parallel(DataSet_outputFolder, DataSet_FileName, Cluster_outputFolder, outputname)% mapreduce 聚类
Cluster_outputFolder = 'D:\Program Files\MATLAB\R2018a\work\特征提取\outputData\Cluster_tallMapreduce';
fun_FeatureCluster_tallMapreduce(DataSet_outputFolder, DataSet_FileName, Cluster_outputFolder, outputname)
%% 目标图像
ObjSetFolder = 'D:\Program Files\MATLAB\R2018a\work\特征提取\dataSet';
ObjSetimds = imageDatastore(ObjSetFolder);
ObjSetImageFile = ObjSetimds.Files;
[~,ObjSetImageFileName] = cellfun(@fileparts,ObjSetImageFile,'uniformOutput',false);
warning off
for i=1:length(ObjSetImageFile)
queryImage = ObjSetImageFile{i};
[retrievalImageHomePage,retrievalImageSimilarity] = fun_ImageRetrieval_Cluster(queryImage, Cluster_outputFolder, outputname); % todo :返回距离和相似度
% [retrievalImageHomePage,retrievalImageSimilarity, retrievalImageURL] = fun_ImageRetrieval_NoCluster(ImageURL);
figure
montage(retrievalImageHomePage, 'Size', [10 10]);
saveas(gcf,['D:\Program Files\MATLAB\R2018a\work\特征提取\fig\', ObjSetImageFileName{i},'.jpg']);
end
warning on
% % 展示目标图片i的检索结果
% subplot(3, 5, [1:5])
% image(imread(char(queryImage)));
% axis equal
% axis off
% title('目标图像')
% for j = 1:10
% retrieval_ip = retrievalImageHomePage{j};
% picture_data = imread(retrieval_ip);
% subplot(3, 5, 5+j)
% image(picture_data);
% axis equal
% axis off
% end
if ~exist('D:\Program Files\MATLAB\R2018a\work\特征提取\fig', 'dir')
mkdir(['D:\Program Files\MATLAB\R2018a\work\特征提取\fig', '\fig'])
end
% saveas(gcf, ['D:\Program Files\MATLAB\R2018a\work\特征提取\fig',]);
%% 添加新数据
NewDataSet_outputFolder = 'D:\Program Files\MATLAB\R2018a\work\特征提取\outputData'; %
NewDataSet_FileName = '\NewDataSet_FeatureVec.txt'; % 新数据集文件(FeatureVec)
DataSet_outputFolder = 'D:\Program Files\MATLAB\R2018a\work\特征提取\outputData';
DataSet_FileName = '\DataSet_FeatureVec.txt'; % 总数据集文件
errorDownload_file = 'D:\Program Files\MATLAB\R2018a\work\特征提取\outputData\errorDownload_file.txt';
fun_ImageUrlSqlTransformDataSet(DataSet_outputFolder, DataSet_FileName, NewDataSet_outputFolder, NewDataSet_FileName, errorDownload_file)
try
load([DataSet_outputFolder, '\NumAccumulaNewDataSet.mat'])
catch
n_AccumulaNewDataSet = 0;
end
Cluster_outputFolder = 'D:\Program Files\MATLAB\R2018a\work\特征提取\outputData\Cluster_parallel';
outputname = 'first';
n_AccumulaNewDataSet = fun_AddNewData(n_AccumulaNewDataSet,...
NewDataSet_outputFolder, NewDataSet_FileName,...
DataSet_outputFolder, DataSet_FileName,...
Cluster_outputFolder, outputname);
save([DataSet_outputFolder, '\NumAccumulaNewDataSet.mat'], 'n_AccumulaNewDataSet')
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。