フィルターのクリア

How could I convert my png images to tiff?

15 ビュー (過去 30 日間)
Leila
Leila 2020 年 9 月 30 日
コメント済み: Ameer Hamza 2020 年 9 月 30 日
this is my code:
clc; clear; close all;
imagePath = 'C:\Users\images';
savePath = 'C:\Users\images_tiff';
fileNames = dir(imagePath);
fileNames = fileNames(3:end);
for i = 1:size(fileNames,1)
varH =fileNames(i).name;
I= imread([imagePath '\' varH]);
imwrite(I ,[savePath '\' varH,'.tiff'],'tiff')
end
it convert my images ti tiff but add .png extension to them
  2 件のコメント
KSSV
KSSV 2020 年 9 月 30 日
What about the present code? Any error?
Leila
Leila 2020 年 9 月 30 日
it convert my images to tiff but add .png extension to them

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

回答 (2 件)

Ameer Hamza
Ameer Hamza 2020 年 9 月 30 日
編集済み: Ameer Hamza 2020 年 9 月 30 日
Your code will fail if the directly contain any other files other than png files (even hidden files). You need to specify the file type. Try this
clc; clear; close all;
imagePath = 'C:\Users\LENOVO\Dropbox\My PC (DESKTOP-A78LL8Q)\Desktop\task\grayScale';
savePath = 'C:\Users\LENOVO\Dropbox\My PC (DESKTOP-A78LL8Q)\Desktop\task\grayScale_tiff';
fileNames = dir([imagePath '\*.png']); % specify png here
for i = 1:numel(fileNames)
varH =fileNames(i).name;
I= imread([imagePath '\' varH]);
imwrite(I ,[savePath '\' varH(1:end-4),'.tiff'],'tiff')
end
  3 件のコメント
Leila
Leila 2020 年 9 月 30 日
thank you, it works
Ameer Hamza
Ameer Hamza 2020 年 9 月 30 日
I am glad to be of help!!!

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


Walter Roberson
Walter Roberson 2020 年 9 月 30 日
varH =fileNames(i).name;
That variable is going to contain the file name that you are reading in, without any directory part, but including the file extension.
imwrite(I ,[savePath '\' varH(1:end-4),'.tiff'],'tiff')
It still has that file extension in that line, and as well you are adding on a second file extension .tiff .
[~, basename, ~] = fileparts(varH);
newfile = fullfile(savePath, [basename '.tiff']);
imwrite(I, newfile, 'tiff');

カテゴリ

Help Center および File ExchangeImport, Export, and Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by