1 Star 0 Fork 0

songyanyi/Image feature extraction

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
main_demo.m 4.51 KB
一键复制 编辑 原始数据 按行查看 历史
songyanyi 提交于 2018-09-26 10:06 . first commit
%% 图片数据库转化为特征向量
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')
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Matlab
1
https://gitee.com/songyanyi/Image-feature-extraction.git
[email protected]:songyanyi/Image-feature-extraction.git
songyanyi
Image-feature-extraction
Image feature extraction
master

搜索帮助