Borrar filtros
Borrar filtros

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

3 visualizaciones (últimos 30 días)
Janez Novak
Janez Novak el 29 de Dic. de 2020
Comentada: Walter Roberson el 29 de Dic. de 2020
I am plotting 4 different thresholded t-maps using .nii files. My first three t-maps are executed correctly. But there seems to be a problem with my fourth. Meaning that using the same script (and functions) works 3 out of 4 times. I attached error below. Matlab R2018a.
function Y_rgb = sd_slice_to_rgb(Y, layer, settings)
% Panel dimensions
pandims = settings.slice.pandims;
% Use slover to scale slice to color map indices
Y_map_i = pr_scaletocmap(Y, ...
layer.color.range(1), ...
layer.color.range(2), ...
layer.color.map, ...
[0 256 0]);
% Convert to RGB - Error in next line
Y_rgb = reshape(layer.color.map(Y_map_i(:),:), ...
pandims);
Y_rgb(Y_rgb > 1) = 1;
end
% sd_display (line 93)
Y_rgb = sd_slice_to_rgb(Y_c,layers(i_layer),settings);
  2 comentarios
Walter Roberson
Walter Roberson el 29 de Dic. de 2020
Some element of Y_map_i is greater than 64 but layer.color.map only has 64 elements.
We do not know anything about pr_scaletocmap to know how that could come about.
Janez Novak
Janez Novak el 29 de Dic. de 2020
function [img, badvals]=pr_scaletocmap(inpimg,mn,mx,cmap,lrn)
% inpimg - matrix containing image to scale
% mn - image value that maps to first value of colormap
% mx - image value that maps to last value of colormap
% cmap - 3xN colormap
% lrn - 1x3 vector,
% If lrn value is 0, then colormap values are set to 1, and
% indices to these values are returned in badvals (below)
% img - inpimg scaled between 1 and (size(cmap, 1))
% badvals - indices into inpimg containing values out of range, as
cml = size(cmap,1);
if nargin < 5
lrn = [1 cml 0];
end
img = (inpimg-mn)/(mx-mn); % img normalized to mn=0,mx=1
if cml==1 % values between 0 and 1 -> 1
img(img>=0 & img<=1)=1;
else
img = img*(cml-1)+1;
end
outvals = {img<1, img>cml, isnan(img)};
img= round(img);
badvals = zeros(size(img));
for i = 1:length(lrn)
if lrn(i)
img(outvals{i}) = lrn(i);
else
badvals = badvals | outvals{i};
img(outvals{i}) = 1;
end

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 29 de Dic. de 2020
[0 256 0]);
The 256 there instructs that any values that would map outside of the colormap length should be replaced with 256, no matter what the length of the colormap is. You have at least one value that maps to outside the colormap, such as if your layer.color.range values are not correct for Y
  2 comentarios
Janez Novak
Janez Novak el 29 de Dic. de 2020
Using function slover inside SPM module, one can plot threshold t-map with GUI.
slover('basic_ui');
If I apply the same values for layer.color.range as in my script, I get correct plot. One threshold t-map goes from [1.67 5.8834] and the other one from [1.67 10.8384].
So I can't fully grasp how to get rid of my error.
Walter Roberson
Walter Roberson el 29 de Dic. de 2020
Put a breakpoint at
outvals = {img<1, img>cml, isnan(img)};
and execute the code. When it gets to the breakpoint, step one line so that outvals is assigned to. Now ask
nnz(outvals{2})
if the reported number is not zero then
img(outvals{i}) = lrn(i);
is going to have an meaningful effect.
When that happens, you need to examine
max(inpimg(:))
min(inpimg(:))
mx
mn
max(img(:))
cml
[BR, BC] = find(inpimg > mx, 1);
if ~isempty(BR)
fprintf('inpimg(%d,%d) = %g which is greater than the declared max, %g\n', BR, BC, inpimg(BR,BC), mx)
end

Iniciar sesión para comentar.

Categorías

Más información sobre Purple en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by