MATLAB: I read set of images and I removed the borders of them, I need to save the resulted images in a new folder but i couldnt. I used this code but I didnt get a result, I need a help, plz

image processingpreprocessingwrite images to file

srcFiles = dir('C:\Users\..\ImagesWithBorder\*.tif'); % the folder in which our images exists
for i = 1 : length(srcFiles)
filename = strcat('C:\Users\..\ImagesWithBorder\',srcFiles(i).name);
I = imread(filename);
% figure, imshow(I);
J = rgb2gray(I);
A=double(J);
[r c]=size(A);
for row = 1 : r
for col = 1 : c
if J(row,col) >= 90
J(row,col) = 0;
end
end
end
J(all(J==0,2),:)=[]
J(:,all(J==0,1))=[]
Finalfilename = sprintf('C:\\Users\\ahmadjalal2013\\Desktop\\Thesis_Images\\ImagesWithoutBorder\\%02d',i);
imwrite ( J, 'Finalfilename', 'tif');
end

Best Answer

You shouldn't have single quotes around the filename when you pass it into imwrite(). Here, use this code instead:
outputFolder = 'C:/Users/ahmadjalal2013/Desktop/Thesis_Images/ImagesWithoutBorder';
baseFileName = sprintf('%02d.tif', i);
fullFileName = fullfile(outputFolder, baseFileName); % Prepend folder.
imwrite(J, fullFileName);
Note that there is a .tif extension in the baseFileName so you do not need to pass it into imwrite(). Also note that forward slashes work just fine with Windows in path names.
Related Question