i have few images, i want to create folders, and names of folders should be identical to images. and want to save those images in folders having identical names.

1 回表示 (過去 30 日間)
Kindly help me through coding, I am new to Matlab, and its difficult for me to do this task, I need your help.

採用された回答

Image Analyst
Image Analyst 2017 年 12 月 2 日
Try this:
% Specify the folder where the files live.
myFolder = 'D:\My Pictures\Misc'; % Wherever...
% Check to make sure that folder actually exists. Warn user if it doesn't.
if ~isdir(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder);
uiwait(warndlg(errorMessage));
return;
end
% Get a list of all files in the folder with the desired file name pattern.
filePattern = fullfile(myFolder, '*.PNG'); % Change to whatever pattern you need.
theFiles = dir(filePattern);
for k = 1 : length(theFiles)
baseFileName = theFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
% Now do whatever you want with this file name,
% such as reading it in as an image array with imread()
imageArray = imread(fullFileName);
imshow(imageArray); % Display image.
drawnow; % Force display to update immediately.
% 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);
% Copy file to that folder
copyfile(fullFileName, outputFileName);
fprintf(' Copied %s to the folder called %s.\n', baseFileName, outputFolder);
end
  3 件のコメント
saeeda saher
saeeda saher 2017 年 12 月 3 日
編集済み: saeeda saher 2017 年 12 月 3 日
I am not understanding how to put this code in above code to detect face from each images and crop the face and then save the cropped face as image in created folders. Instead of copy file i want to save cropped face in the folder of image. This code is for face detection and cropping face...
FaceDetect = vision.CascadeObjectDetector;
FaceDetect.MergeThreshold = 7 ;
BB = step(FaceDetect,img); 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(img,BB(i,:));
subplot(6,6,i);
imshow(J);
end
end
Image Analyst
Image Analyst 2017 年 12 月 3 日
After imshow you need to call imwrite():
drawnow;
imshow(J, filename);

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by