How to Save image Features in .mat file??
Show older comments
I am trying to extract facial features from image using HOG and trying to save them in .mat file, but when i run my code it saves the features of all images in one column. I want to save the features of each image in separate row.
Here is my CODE:
myFolder = 'folder'; % or whatever.
if ~isdir(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder);
uiwait(warndlg(errorMessage));
return;
end
filePattern = fullfile(myFolder, '*.jpg');
matFiles = dir(filePattern);
for k = 1:length(matFiles)
baseFileName = matFiles(k).name;
img = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', img);
storedStructure = imread(img);
% Now do whatever you need to do with the structure you recalled.
%figure % New figure, do not specify the index
%imshow(img);
FaceDetect = vision.CascadeObjectDetector;
FaceDetect.MergeThreshold = 7 ;
BB = step(FaceDetect,storedStructure); %figure(2),imshow(img);
for i = 1:size(BB,1)
rectangle('Position',BB(i,:),'LineWidth',3,'LineStyle','- ','EdgeColor','r');
end
% figure
for i = 1:size(BB,1)
J= imcrop(storedStructure,BB(i,:));
%subplot(6,6,i);
figure
imshow(J);
% Create a folder with the base file name
[~, baseFileNameNoExt, ~] = fileparts(baseFileName);
outputFolder = fullfile(myFolder, baseFileNameNoExt);
if ~exist(outputFolder, 'dir')
mkdir(outputFolder);
fprintf('Created folder : %s\n', outputFolder);
end
% Prepare output filename
outputFileName = fullfile(outputFolder, baseFileName);
% Write file to that folder
imwrite(J, outputFileName);
fprintf(' Copied %s to the folder called %s.\n', baseFileName, outputFolder);
end
end
J
HOG(J)
X=HOG(J)
save('features.mat','J');
Accepted Answer
More Answers (1)
Walter Roberson
on 27 Apr 2018
0 votes
You are doing a loop with imcrop, but you are only storing the output for the current iteration in J. Afterwards, J is going to have the value it had on the last iteration of the loop. You are then applying HOG only to that one cropped version.
You should be calculating the HOG inside the loop and saving all of the results.
Categories
Find more on Language Support in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!