Index in position 2 exceeds array bounds (must not exceed 1).

2 vues (au cours des 30 derniers jours)
Rock Interpreter
Rock Interpreter le 24 Juil 2020
Commenté : Rock Interpreter le 27 Juil 2020
Hello!
I am getting an error while running the code as given below"
Index in position 2 exceeds array bounds (must not exceed 1).
Error in Untitled4 (line 32)
imagesc(data{1,3});
The main code is:
% A = imread('Filename');
%%
close all;
load_data_flag =1;
%% Load data
if load_data_flag ==1;
%
% las_file = load('Curves.txt');
% log_depth = las_file(:,1);
% caliper3 = las_file(:,3:5); % 1) depth, 3-4-5) calipers
% caliper_ave = mean(caliper3(:,3:end),2);
%%
tifffiles = dir('*.tif');
nfiles = length(tifffiles);
for n= 1:nfiles;
data{n} = imread(tifffiles(n).name);
end % endfor
% concatenate all log data into one matrix
% DATA = data;
DATA = data{1,1};
for i = 2:length(data(1,:))
DATA=vertcat(DATA,data{1,i});
end
%% Subsection of data
clf
imagesc(data{1,3});
reply = input ('Input depth axis, subsection and 0-360 coordinates?[Y]/[N]:', 's');
if reply == ('Y')||('y')
I would appreciate if anyone can help?

Réponse acceptée

Walter Roberson
Walter Roberson le 24 Juil 2020
You only have one .tif file in your current directory so you are only storing data{1} .
  5 commentaires
Walter Roberson
Walter Roberson le 24 Juil 2020
load_data_flag = 1;
%% Load data
if load_data_flag == 1
force_rows = 512; force_columns = 512;
tifffiles = dir('*.tif');
nfiles = length(tifffiles);
data = cell(nfiles, 1);
for n = 1:nfiles
input_image = imread(tifffiles(n).name);
data{n} = imresize(input_image, [force_rows, force_columns]);
end % endfor
% concatenate all log data into one matrix
DATA = cat(ndims(data{1})+1, data{:});
end
This code forces all images to be the same size, controlled by force_rows and force_columns. Using a fixed aspect ratio can distort the image. You should think more about how you want to handle the case where the images are not the same size. Sometimes it makes sense to imresize() them to a common size. Sometimes it makes more sense to pad them to a common size. Sometimes it makes more sense to pad them as needed to fit the widest and heighest image. Sometimes it makes most sense to pad relative to the center rather than padding on bottom or right all the time. Sometimes it makes more sense to do image registration to find the best scaling and translation to bring them into alignment.
Rock Interpreter
Rock Interpreter le 27 Juil 2020
Dear Walter,
Many thanks for your kind response. I am still struglling to get the image for further analyis. Would appreciate if you could help.
Now the error is:
Index in position 2 exceeds array bounds (must not exceed 1).
Error in Untitled4 (line 36)
imagesc(data{1,n});
The main script is given below:
-----------------------------------------------------
close all;
load_data_flag =1;
%% Load data
if load_data_flag ==1;
force_rows = 512; force_columns = 512;
tifffiles = dir('*.tif');
nfiles = length(tifffiles);
data = cell(nfiles, 1);
for n = 1:nfiles
input_image = imread(tifffiles(n).name);
data{n} = imresize(input_image, [force_rows, force_columns]);
end % endfor
% concatenate all log data into one matrix
DATA = cat(ndims(data{1})+1, data{:});
end
%% Subsection of data
clf
imagesc(data{1,n});
reply = input ('Input depth axis, subsection and 0-360 coordinates?[Y]/[N]:', 's');
if reply == ('Y')||('y')
%% 1) DEPTH AXIS - INPUT
[ null, depths] = ginput(2); % log input for depth axis
%% 2) SUBSECTION - INPUT
[L, r] = ginput(2); % input for subsection of data
left = ceil(L(1,1));
right = ceil(L(2,1));
subsection_data = DATA;
subsection_data = subsection_data(:,left:right,:); % need last colon cause its image with RGB
clf
imagesc(subsection_data);
%% 3) 0-360 AZIMUTH - INPUT
[beg, en] = ginput(2); %coordinates for 0-360 the axis of FMI
zero = ceil(beg(1,1));
three60 = ceil(beg(2,1));
end % endif
%%
% appended = vertcat(A,B) ==> appended = [A | B]'
imagesc(subsection_data);
counterrow=0;
% countery=0;
------------------------------------------------------

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Read, Write, and Modify Image dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by