How to read and pre-process the multiple images and write in specific location?

1 Ansicht (letzte 30 Tage)
function preprocessing_multiple
srcFiles = dir('C:\Users\LENOVO\Desktop\Genuine\1\*.png'); % the folder in which ur images exists
for i = 1 : length(srcFiles)
filename = strcat('C:\Users\LENOVO\Desktop\Genuine\1\',srcFiles(i).name);
I = rgb2gray(imread(filename));
imshow(I)
I2=medfilt2(I);
figure,imshow(I2)
imwrite(I2,fullfile('C:\Users\LENOVO\Desktop\','*.png'));
end
I got error in above code:
Error using imwrite (line 454)
Unable to open file "C:\Users\LENOVO\Desktop\*.png" for writing. You may not
have write permission.
Error in preprocessing_multiple (line 11)
imwrite(I2,fullfile('C:\Users\LENOVO\Desktop\','*.png'));

Akzeptierte Antwort

Geoff Hayes
Geoff Hayes am 11 Feb. 2019
Regina - in your line of code
imwrite(I2,fullfile('C:\Users\LENOVO\Desktop\','*.png'));
which file are you trying to write to? You are not specifying a file name and are instead using the wildcard character. Try changing the above line of code so that you explicitly set the filename to which you want to write the I2 data to.
  3 Kommentare
Geoff Hayes
Geoff Hayes am 13 Feb. 2019
Regina - look closely at your code
for i = 1 : length(srcFiles)
filename = strcat('C:\Users\LENOVO\Desktop\Genuine\1\',srcFiles(i).name);
I = rgb2gray(imread(filename));
imshow(I)
I2=medfilt2(I);
figure,imshow(I2)
imwrite(I2,fullfile('C:\Users\LENOVO\Desktop\','*.png'));
end
The code is looping over all of the files that you have found, reading the file, doing some processing, and then (trying) to write to an incorrectly named file. So you won't be able to save all the preprocessed images in one line code. Instead, you can save each preprocessed file one at a time by replacing
imwrite(I2,fullfile('C:\Users\LENOVO\Desktop\','*.png'));
with
imwrite(I2,fullfile('C:\Users\LENOVO\Desktop\', srcFiles(i).name));
The above assumes that you want to write to a file with the same name as the original file (just in a different folder).
Regina N
Regina N am 14 Feb. 2019
Actually i am new to matlab....so....bt thank you so much for helping me..it works..thanx again

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB Support Package for Raspberry Pi Hardware finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by