Loop with different images on Matlab
Show older comments
I have a question about how can I create a loop. I'm going to try to simplify. I have three images (the real problem has a huge images). For example:
image1.tif
image2.tif
image3.tif
On the other hand, I have a text file (I cannot introduce this on the code directly) with two different parameters for each image. For example:
Parameterimage1_1= 1.2; %value related to image1
Parameterimage1_2= 2.3; %corresponds to image1
Parameterimage2_1= 5.3; %corresponds to image2
Parameterimage2_2= 2.4; %corresponds to image2
(...)
What I need to do is to read the text file and then, apply two different parameters for each image in a loop to calculate. What I have done is the following:
Image1= imread ('image1.tif');
Image2= imread ('image2.tif');
Image3= imread ('image3.tif');
Data= READINGPARAMETERS(parameters)
param1= Data.param1;
param2= Data.param2;
param3=Data.param3;
(...)
Image1_out= param1*Image1/param2;
Image2_out= param3*Image1/param4;
Image2_out= param5*Image1/param6;
imwrite(Image1_out, 'G:\Image1_out.tiff','tiff');
imwrite(Image2_out, 'G:\Image2_out.tiff','tiff');
function [Data] = READINGPARAMETERS(parameters)
fid = fopen(parameters); % I have defined the path previously
text = fscanf(fid, '%c');
posini= strfind(text,'=');
posfin= strfind(text,';');
Datos.param1= str2num(texto(posini(1)+1 : posfin(1)-1));
Datos.param2= str2num(texto(posini(2)+1 : posfin(2)-1));
Datos.param3= str2num(texto(posini(3)+1 : posfin(3)-1));
(...)
return
My question is that I don't know how to create the loop for that and with every image, uses two parameteres. Usually, I do it in that way but I don't know how to indicate that has to take the values.
for k = 1:length(tifFiles)
baseFileName = tifFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
imageArray = imread(fullFileName);
AND here the process
imwrite(imageArray, fullFileName);
Any kind of help would be appreciated,
Greetings,
Accepted Answer
More Answers (0)
Categories
Find more on Convert Image Type in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!