How to save image with its original name?

조회 수: 4 (최근 30일)
Awais Khan
Awais Khan 2019년 12월 5일
편집: KALYAN ACHARJYA 2019년 12월 6일
Hi, actually i am trying to do a task, i saved image dataset in 'imds' and want to save same images after applying some operation in a new folder but with same name. i am successed to save images in a folder using imwrite command but facing problem to assigning original name to that newly saved images.
For example "D:\Matlab Coding of Projects\demo_dataset\cam_a\003_0.bmp" in this path 003_0.bmp is image name i want to save image with same name after applying operation.
i am using "imwrite(rgbImage2,['D:\Matlab Coding of Projects\ImageFolder\HazyImages\',num2str(i),'.bmp']);" line of code for saving image in new folder. but image is not save with its original name so what can i do? help me in this regards.

채택된 답변

KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 12월 5일
편집: KALYAN ACHARJYA 2019년 12월 5일
Please see this example, you may able to fix it
Images=dir('C:\Lab\Hand stage 4\*.png'); % Complete path
outDirectory='C:\Lab\result_hand_2101\'; % To save image Create folder "result_hand_2101" in the path
for i=1:length(Images)
ImgName=strcat('C:\Lab\Hand stage 4\',Images(i).name);
grayImage=((imread(ImgName)));
%% say result image is enhancedImage1
imwrite(enhancedImage1,strcat(outDirectory,Images(i).name));
end
  댓글 수: 2
Awais Khan
Awais Khan 2019년 12월 6일
i appreciate your answer,but by using "imds = imageDatastore" how can we access name like you are access name through "Images(i).name".
if your answer is through label of imds we access image name, so it is not right because label contains only sub folder name of dataset.
KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 12월 6일
편집: KALYAN ACHARJYA 2019년 12월 6일
In my answer the write/save images names is same as original image file names.

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

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by