Issue with button taking in inputs from multiple list buttons to highlight regions of atlas image. Error: Brace indexing is not support for variables of this type

1 vue (au cours des 30 derniers jours)
So I am creating an app that highlights certain regions on the area with different colors when selected from a list button. So far I have been successful when there is only one list to choose from. Here is my code for that:
% Load Atlas
% Relies on https://www.fieldtriptoolbox.org/template/atlas/ and
% https://github.com/fieldtrip/fieldtrip/tree/master/template/atlas and
% https://www.gin.cnrs.fr/en/tools/aal/
aalAtlas = ft_read_atlas('ROI_MNI_V4.nii');
BrainImage = ones(91, 109,'int8');
BrainImage(:,:) = aalAtlas.tissue(:, :, 50) %the tissue is part of the 3D BrainImage of the Atlas that looks at tissue
% explanation for below: https://www.mathworks.com/matlabcentral/answers/24865-converting-cell-of-strings-in-arry-or-cell-of-numbers
%Convert it to a proper format to allow parts of images to highlighted/brighter
String_region = sprintf('%s ', app.CerebralAreasListBox.Value{:});
List_of_specifed_regions_array = sscanf(String_region, '%f');
%put it in a for loop to display each section
for slice = 1:91
BrainImage(:,:) = aalAtlas.tissue(:, :, slice);
ColorBrainImage = ind2rgb(BrainImage, copper);
% Make those 3 regions a 5 times brighter value brighter.
ColorBrainImage(regions) = uint8(50 * double(ColorBrainImage(regions))); %double allows to multipy with decimals and uint brings it back to whole number
BBrainImage = imresize(ColorBrainImage,9);
imshow(BBrainImage)
end
But then I run into issues when I want to have multiple lists to choose from that can select their own respective regions of the brain. This is my code when I try to include the other two lists, which I want to add extra eventaully, but it keeps failing. My goal is to have each list show their regions in a different color, but for now I at least want to have them work on selecting regions on their own. I keep on getting an error that says "Brace indexing is not supported for variables of this type." I don't understand why that is when is worked in the lines above it. Thank you for the help in advance!
% Button pushed function: BrainAtlasButton
function LoadAtlas(app, event)
% Load Atlas
% Relies on https://www.fieldtriptoolbox.org/template/atlas/ and
% https://github.com/fieldtrip/fieldtrip/tree/master/template/atlas and
% https://www.gin.cnrs.fr/en/tools/aal/
aalAtlas = ft_read_atlas('ROI_MNI_V4.nii');
BrainImage = ones(91, 109,'int8');
BrainImage(:,:) = aalAtlas.tissue(:, :, 50) %the tissue is part of the 3D BrainImage of the Atlas that looks at tissue
% explanation for below: https://www.mathworks.com/matlabcentral/answers/24865-converting-cell-of-strings-in-arry-or-cell-of-numbers
%Convert it to a proper format to allow parts of images to highlighted/brighter
String_region = sprintf('%s ', app.CerebralAreasListBox.Value{:});
List_of_specifed_regions_array = sscanf(String_region, '%f');
String_region_2 = sprintf('%s ', app.CerebralAreasListBox_2.Value{:});
List_of_specifed_regions_array_2 = sscanf(String_region_2, '%f'); %ERROR: Brace indexing is not supported for variables of this type.
String_region_3 = sprintf('%s ', app.CerebralAreasListBox_3.Value{:});
List_of_specifed_regions_array_3 = sscanf(String_region_3, '%f');
%put it in a for loop to display each section
for slice = 1:91
BrainImage(:,:) = aalAtlas.tissue(:, :, slice);
regions_1 = ismember(BrainImage, List_of_specifed_regions_array);
regions_2 = ismember(BrainImage, List_of_specifed_regions_array_2 );
regions_3 = ismember(BrainImage, List_of_specifed_regions_array_3 );
regions = (regions_1).*(regions_2).*(regions_3)
ColorBrainImage = ind2rgb(BrainImage, copper);
% Make those 3 regions a 5 times brighter value brighter.
ColorBrainImage(regions) = uint8(50 * double(ColorBrainImage(regions))); %double allows to multipy with decimals and uint brings it back to whole number
BBrainImage = imresize(ColorBrainImage,9);
imshow(BBrainImage)
end

Réponses (1)

Varun
Varun le 28 Déc 2023
Hi Alexandar,
I understand that you are facing issues when you want to have multiple lists to choose that can select their own respective regions of the brain. You have provided the code and facing error in the line number 70:
List_of_specifed_regions_array_2 = sscanf(String_region_2, '%f'); %ERROR: Brace indexing is not supported for variables of this type.
I reproduced the error at my end and found the root cause.
You are using 3 list boxes namely “CerebralAreasListBox”, “CerebralAreasListBox_2” and “CerebralAreasListBox_3”. If you notice at line number 159, 171 and 183 the default values set are {‘13’}, ‘11’ and ‘8’ respectively. Here, the default value {'13'} for “CerebralAreasListBox” is cell array whereas default values '11' and '8' for other 2 list boxes are strings.
So, app.CerebralAreasListBox.Value{:} works for data type of cell array whereas, these brace indexing fails for data type of string.
To resolve this issue, you can simply use
app.CerebralAreasListBox_2.Value %line 69
and
app.CerebralAreasListBox_3.Value %line 72
without any brace indexing for “CerebralAreasListBox_2” and “CerebralAreasListBox_3”.
Alternatively, you can also try to delete “CerebralAreasListBox” and create a new one again which have value’s data type as string by default. And then use “app.CerebralAreasListBox.Value” i.e. without any brace indexing like other two list boxes.
Please refer to the following MATLAB documentations to learn more:
Hope it helps.

Catégories

En savoir plus sur Image Processing Toolbox dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by