I get only one image in my directory while while executing the below code. Please help to come out from this.
Info
This question is closed. Reopen it to edit or answer.
Show older comments
srcFile =dir('C:\Users\Dell\Desktop\python tutorials\matlab\myfiles\matlab\myfiles\Dataset 2\*.tif');
for s=1:length(srcFile)
filename=strcat('C:\Users\Dell\Desktop\python tutorials\matlab\myfiles\matlab\myfiles\Dataset 2\',srcFile(s).name);
a=imread(filename);
b=double(a(:));
lem=225;
minim=min(b(:));
maxim=max(b(:));
[m,n]=size(a);
x=zeros(1,225);
q=zeros(1,225);
w=zeros(1,225);
r=zeros(1,225);
E=zeros(1,225);
u=zeros(1,225);
for i=1:m
for j=1:n
g=a(i,j);
x(i,j)=((g-minim)./(maxim-minim));
q(i,j)=((1+lem)*x(i,j))./(1+lem*x(i,j));
w(i,j)=(1-x(i,j))./(1+(3*lem*x(i,j))+(lem^2*x(i,j))+x(i,j));
r(i,j)=1-q(i,j)-w(i,j);
E(i,j)=(1./x(i,j))*(sum(sum(r(i,j)*exp(1-r(i,j)))));
u(i,j)=maxim*(E(i,j)+lem);
t=q(i,j)^1.25;
for y=0:0.1:1
if t<=0.5
p(i,j)=2*(t^2);
else
p(i,j)=1-2*((1-t)^2);
end
end
end
mkdir('myimages')
figure, imshow(p);
imwrite(p,'myimages/testfile.tif','tif')
end
end
Answers (1)
Walter Roberson
on 7 Jun 2020
imwrite(p,'myimages/testfile.tif','tif')
You are always writing to the same output location. I suggest:
[~, basename] = fileparts(srcFile(s).name);
outputname = fullfile('myimages', [basename '.tif'], 'tif');
This will output into the same file name as the input, except in the myimages directory.
srcFile =dir('C:\Users\Dell\Desktop\python tutorials\matlab\myfiles\matlab\myfiles\Dataset 2\*.tif');
I recommend that you learn to use fullfile() such as
projectdir = 'C:\Users\Dell\Desktop\python tutorials\matlab\myfiles\matlab\myfiles\Dataset 2';
srcFile = dir( fullfile(projectdir, '*.tif') );
...
filename = fullfile(projectdir, srcFile(s).name);
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!