I have a iterate undistorttImage function question for version 2016a

2 comentarios

The code shown below is what I used to solve my metadata problem. In it I store image capture date only:
load('C:\mypath\workspace.mat')
p = which('G0011363.JPG');
filelist = dir([fileparts(p) filesep '*.JPG']);
fileNames = {filelist.name};
fileNames_size = size(fileNames,2);
number_of_colums = fileNames_size;
for k = 1:number_of_colums
k2 = imfinfo(fileNames{k});
k3 = k2.FileModDate;
imwrite(undistortImage(imread(fileNames{k}), cameraParams2cof, 'OutputView', 'valid'), (strcat(int2str(k), '_R2_3COF.jpg')), 'jpg', 'comment', k3);
end
This is the code I finally ended up using. Note: DateTime and total seconds elapsed are added to the file name in lieu of standard image metadata.
load('C:\redacted_lol\workspace.mat')
p = which('G0017317.JPG');
filelist = dir([fileparts(p) filesep '*.JPG']);
fileNames = {filelist.name};
fileNames_size = size(fileNames,2);
number_of_colums = fileNames_size;
k5 = 0;
for k = 1:number_of_colums
k2 = imfinfo(fileNames{k});
k3 = k2.DateTime;
k4 = strrep(k3(12:19), ':', '-');
k5 = k5 + 2;
imwrite(undistortImage(imread(fileNames{k}), cameraParams2cof, 'OutputView', 'valid'), (strcat(int2str(k5), 'SECONDS_LEFTT_', k4, '.png')), 'png', 'comment', k3);
end

Respuestas (1)

Then don't pass in the image, pass in the index and the cell array
function output = undistortImage(filenames, i)
try
output = []; % Initialize
filename = filenames{i};
originalImage = imread(filename);
% More code....
DO NOT have the output variable change it's name with the loop index - bad bad idea. See http://matlab.wikia.com/wiki/FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F
Put the output image into a cell array if you really, really need to keep it after your loop exits.
allImages{k} = undistortImage(filenames, k); % Save image into a cell array and use up a huge amount of memory.
Normally one would just call it thisImage and consume it during the same iteration and overwrite it on every iteration
thisImage = undistortImage(filenames, k); % thisImage will get replaced every iteration and is more memory efficient.
By the way, don't use i and j as loop iterators because they stand for the imaginary variable. That's why I suggest using k instead.

La pregunta está cerrada.

Etiquetas

Preguntada:

el 11 de Ag. de 2016

Cerrada:

el 20 de Ag. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by