フィルターのクリア

Why am I getting an error 'Subscript indices must either be real positive integers or logicals.'

1 回表示 (過去 30 日間)
Why am I getting this error?
for k = 1 : numel(grayImage)
inputIndex = thisPhase(k);
grayImage(k) = uint8(map1(inputIndex));
end

回答 (2 件)

Walter Roberson
Walter Roberson 2016 年 3 月 23 日
What do not know what thisPhase is, and we do not know what map1 . But if thisPhase() can contain non-integer values then you would get that error.
In particular grayscale images can be implemented four different ways in MATLAB:
  • as integer values stored in an integer data type such as uint8 data or uint32. The associated brightness is TheData/intmax(class(TheData)) such as 123/255 for the stored value 123. In this kind of grayscale image, the integer value 0 is valid and needs to be taken into account
  • as floating point values in the range 0 to 1 stored in a floating point array. The associated The associated brightness is the portion given by the floating point value. In this kind of grayscale image, non-integer values of all kinds are valid and need to be taken into account
  • as integer values stored in integer data types such as uint8 data, together with a table of floating point brightness values that are in the range 0 to 1. The integer value is used to index into the brightness table, so there is not necessarily any connection between the integer value itself and the brightness that will result. In this kind of grayscale image, the integer value 0 is valid and is the index of the first entry into the table
  • as floating point integral values stored in a floating point arra. The integer value is used to index into the brightness table, so there is not necessarily any connection between the integer value itself and the brightness that will result. In this kind of grayscale image, the integer value 0 is likely going to be silently treated as if it was 1 but there "should not" be any such values.
So if the datatype is one of the integer data types, the integer 0 is fully expected, either as representing full black, or as representing the first entry in the lookup table. If the datatype is floating point, then values in the range 0 to 1 might be expected, or integers starting from 1 might be expected, depending what the data is being used for. You might notice that only in one of these four possibilities is it safe to assume that you will not have any values that are 0.
  7 件のコメント
Denni Purcell
Denni Purcell 2016 年 4 月 3 日
Sorry, I really don't understand. I am very new to Matlab. What is the code I should try? and can I test something in the command window?
Walter Roberson
Walter Roberson 2016 年 4 月 3 日
What is min(thisPhase(:)) ? What is max(thisPhase(:)) ? What is size(map1) ?

サインインしてコメントする。


Image Analyst
Image Analyst 2016 年 4 月 3 日
Try this:
% Create look up table
lut = map1(thisPhase);
% Apply look up table
grayImage = intlut(grayImage, lut);
That's all. Nothing else. No for loop or anything. Essentially you're using thisPhase to decide how to order map1. Then map1 is being used as a look up table to map grayImage gray levels to new gray levels.
  4 件のコメント
Denni Purcell
Denni Purcell 2016 年 4 月 4 日
What it now looks like:
% Convert stance image for each phase from 'index' to 'grayscale' and
% insert into Phases field: ManipulatedStances
%for k = 1 : numPhases;
%thisPhase = (Phases(k).Stance);
%I = ind2gray(thisPhase,map1);
%Phases(k).ManipulatedStances = I;
%end
% Create thisPhase from the structure array Phases.
thisPhase = [Phases.Stance];
% Create look up table
lut = map1(thisPhase);
% Apply look up table
grayImage = intlut(grayImage, lut);
% Set custom graymap
graymap1 = uint8(.299*map1(:,1) + .587*map1(:,2) + .114*map1(:,3));
grayImage = graymap1(double(thisPhase)+1);
Error:
Subscript indices must either be real positive integers or logicals.
Error in MATLAB_Pbg_CCHR_edit (line 203)
lut = map1(thisPhase);
Do I still nee to have the 'set custom graymap' section?
What do lut and intlut mean?
I think this is the section where the phases is defined if that is of any use:
% Create empty structure with many fields.
Phases = struct('Stance',{},'COF',{},'ManipulatedStances',{},'Feet_Props',{},'Sorted_BB',{},'NumberOfStrikes',{},'Feet_Crops',{});
% Separate each phase from each other
for k = 1 : numPhases;
% r1 and r2 determine the first and last row for the specific phase
r1 = ((k-1)*386)+3;
r2 = ((k-1)*386)+386;
% here, NEW_Stance is cropped from r1 to r2, and columns 1 to 88. This
% crop defines one stance, and it is placed into its own cell in the
% Stance field of the structure Phases
Phases(k).Stance = NEW_Stance(r1:r2,1:88);
end
Walter Roberson
Walter Roberson 2016 年 4 月 4 日
If you use intlut then you should not also do the code at "set custom graymap".
At the beginning of your code you have
map1 = colormap(jet(pCap)); map1(1,:) = [1 1 1];
That defines map1 to be a colormap with pCap entries, but we do not know what the value of pCap is. Unless pCap is at least as great as max(NEW_Stance(:))+1 then you will run into problems with creating the map.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCustom Geometry and PCB Fabrication についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by