How do i store Images on database based on extracted features, then retrieve image based on image query?

Dear Experiences..
  • i have 100 images in folder called (D:\images)..
  • i have extracted feature from every single image where the extracted features are represented as matrix (M x 128),
  • where M refer to feature matrix rows and 128 are feature extracted columns... for all images columns are fixed but rows are differs based on size of an image...
  • feature matrix are numeric matrix...
  • so, i need a way to store all images (100 images) in Database or such other structure content based on image features.. and when i need to retrieve an image .. its compare query image feature matrix to those in database then retrieve similar one... (i think here pairwise distance or such other metric must be used)...
so, i will thank any one can give me an advices or help me in this issue...
thanks..

 채택된 답변

"so, i need a way to store all images (100 images) in Database or such other structure content based on image features.."
Well, you could use containers.Map to use the features as an index to store values. However, since none of your actual images are likely to result in a feature vector that exactly matches, bit for bit, then this is not going to be useful.
In short, don't do that. Instead just store all of the feature vectors for the known images, and then when a probe image comes in, use pdist2 to compare its feature vector to all of the known ones to find the known image that is most like the probe image.

댓글 수: 6

Dear Walter,
your explanation very fine, i think its better to compare all query image features to those in database, my issue is that .. i could not find a way to store image features in database, where every image has a feature matrix consist from (N x 128) feature matrix... N here is not fixed .. so if i have 100 images .. then there are 100 matrix i need to store it in some way... then for query image i compare query image matrix to those in database and find similar images that have minimum distances.. thanks
So store a single numeric array, N x 128. You can save it as a .mat file.
You could also store the file names in the same .mat so that you could work incrementally, by checking the stored file names to see whether you need to calculate the features of a proposed training file or if you have already completed it.
ok, i'm not familar with matlab how could store images features as m.file give me an example and i will apply to all my images, then how i compare two m.file that belongs to two different images
projectdir = 'Master/Folder/The/Training/images/are';
training_subdir = 'train';
savefile_name = fullfile(projectdir, 'feature_record.mat');
if exist(savefile_name, 'file')
try
saved_struct = load(savefile_name);
if isfield(saved_struct, 'all_image_names') && isfield(saved_struct, 'all_image_features')
all_image_names = saved_struct.all_image_names;
all_image_features = saved_struct.all_image_features;
catch
end
end
if ~exist('all_image_names', 'var') || ~exist('all_image_features', 'var')
all_image_names = {};
all_image_features = zeros(0, 128);
end
image_types_to_use = {'.png', '.jpg', '.tiff', '.bmp'};
subdirs = dir( fullfile(projectdir, training_subdir) );
subdirs(~[subdirs.isdir]) = []; %get rid of everything but sub folders
subdir_names = {subdirs.name};
subdirs( ismember(subdir_names, {'.', '..'}) ) = []; %get rid of . and ..
subdir_names = {subdirs.name};
for subdir_idx = 1 : length(subdir_names)
this_subdir = fullfile(projectdir, subdir_names{subdir_idx}) );
this_subdir_files = dir(this_subdir);
subdir_files(~[subdir_files.isdir]) = []; %get rid of folders
subfile_names = {subdir_files.name};
these_file_names = fullfile(this_subdir, {subdir_files.name});
for file_idx = 1 : length(these_file_names)
this_file_name = these_file_names{file_idx};
[~, ~, file_ext] = fileparts(this_file_name);
if ~ismember(file_ext, image_types_to_use); continue; end %are we interested in these kinds of files?
if ismember(this_file_name, all_image_names); continue; end %did we already process this file?
this_feature_vector = extract_features(this_file_name);
if ~isempty(this_feature_vector) %extraction worked
all_image_features(end+1, 1:length(this_feature_vector)) = this_feature_vector;
all_file_names{end+1} = this_file_name;
try
save(savefile_name, 'all_file_names', 'all_image_features');
end
end
end %files within this folder
end %folders
Now all_image_features in an N x 128 array formed by processing all of the image files in all of the subfolders under the training subdirectory of the projectdir folder, and all_image_names is a cell array of character vectors of the corresponding file names. Under the projectdir folder, a .mat file feature_record.mat has been created with the same information.
This code has been created so that if you interrupt the training, or if you add new files or new subdirectories in the training folder, then it will continue where it left off, adding all files to the database that it has not already processed.
With all_image_features in hand, you can process a probe image, extract its features, and then use pdist2() of its feature vector against all_image_features, and determine the minimum distance and the index of the minimum distance. You can then use the index of the minimum distance to index the all_image_names in order to pull out the corresponding file name.
Dear Walter (Experience) i'm sure your code is very smart and great.. may i'm not explain my project work issue clearly .. but i hope to help me for this..
Sir, i'm use SURF algorithm to extract local feature from every image .. where 128 vector length used.. according to the following code .. now every image has (M x 128) feature matrix.. i could not find a place to add SURF code in your program ... then how could query image is calculated against all others.. thanks
A=imread ('D:\images\7_6.jpg');
sample1 =rgb2gray(A);
queryPoints = detectSURFFeatures(sample1);
[queryFeatures, queryPoints] = extractFeatures(sample1, queryPoints,'SURFSize',128);
now we have query_image feature matrix (M x 128)... i need to find matches against all other images feature matrices and retrieve close ones..
how i can create this code in your mention code... with my best regards.
My code line
this_feature_vector = extract_features(this_file_name);
represents a call to a function that takes in a file name and returns a vector of values.
Glancing at detectSURFFeatures and extractFeatures, it looks to me as if the number of features returned can vary from image to image. The code I have written expects that the same number will be returned each time. It is difficult to define the "distance" between two feature vectors if the two have different sizes.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

You can save your (poorly-named) database variable "M" in a .mat file with save().
save(fullFileName, 'M');
You can retrieve M with load().
storedStructure = load(fullFileName); % Get everything fro mfile.
M = storedStructure.M; % Extract the "M" field from the structure.
You can compare your current image's features to M with functions such as find(), ismember(), ismembertol(), or the double equals operator "==", etc.
If you need an "official" database, like Oracle, Access, or something similar, then you might want to get the Database Toolbox.

댓글 수: 1

thanks, i think here use image name... and if some one change names of images in database could not find similar one... please.. i need a help to store one by one image feature to database.. where every image has M x 128 matrix... then for query one i compare its feature matrix to all feature matrices in database.. thanks

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Image Processing and Computer Vision에 대해 자세히 알아보기

질문:

2017년 7월 23일

댓글:

2017년 7월 25일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by