Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

# I get only one image in my directory while while executing the below code. Please help to come out from this.

19 visualizzazioni (ultimi 30 giorni)
uma il 15 Mag 2020
Chiuso: MATLAB Answer Bot il 20 Ago 2021
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);
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

### Risposte (1)

Walter Roberson il 7 Giu 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);

### Community Treasure Hunt

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

Start Hunting!

Translated by