What does the function 'ones' do to a matrix when trying to load an image?

조회 수: 1 (최근 30일)
I am just wondering why we need to put the ones for this code to work. When I get rid of the ones it does not work. Can I get an explanation of why this is?
BrainImage = ones(91, 109,'int8');
  댓글 수: 2
Matt J
Matt J 2022년 7월 8일
편집: Matt J 2022년 7월 8일
The only part of the code you've shown us is the part the single line that uses ones(). If you remove it, you'll be left with no code at all, so of course it won't work!!
Alexandar
Alexandar 2022년 7월 8일
Hello Matt, sorry about that. I did not inlcude the rest of my code. My question is about the basic understanding of why we do this for imaging. Here is the rest of the code you can look at.
% 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'); %creates the variable for the brain image to be read
BrainImage(:,:) = aalAtlas.tissue(:, :, 50) %replaces the one with the tissue is part of the 3D BrainImage of the Atlas that looks at tissue
test_size1 = size(app.CerebralAreasListBox.Value,2) %take into account what is selected, looks at columns only
area_num = ones(1,test_size1) %Changes the # of values selected to a row of that same # of 1's
for j=1:test_size1 % Cycle through the values you have choosen on the list
area_num(j) = str2double(app.CerebralAreasListBox.Value(j));
end
test_size2 = size(app.CerebralAreasListBox_2.Value,2) %take into account what is selected, looks at columns only
area_num2 = ones(1,test_size2)
for j=1:test_size2 % Cycle through lateralization, step change the multiplier
area_num2(j) = str2double(app.CerebralAreasListBox_2.Value(j));
end
test_size3 = size(app.CerebralAreasListBox_3.Value,2) %take into account what is selected, looks at columns only
area_num3 = ones(1,test_size3)
for j=1:test_size3 % Cycle through lateralization, step change the multiplier
area_num3(j) = str2double(app.CerebralAreasListBox_3.Value(j));
end
%put it in a for loop to display each section
for slice = 1:91
BrainImage(:,:) = aalAtlas.tissue(:, :, slice);
ColorBrainImage = ind2rgb(BrainImage, copper);
regions_1 = ismember(BrainImage, area_num);
ColorBrainImage(regions_1) = uint8(2* double(ColorBrainImage(regions_1)));
regions_2 = ismember(BrainImage, area_num2);
ColorBrainImage(regions_2) = uint8(3* double(ColorBrainImage(regions_2)));
regions_3 = ismember(BrainImage, area_num3);
ColorBrainImage(regions_3) = uint8(4* double(ColorBrainImage(regions_3)));
BBrainImage = imresize(ColorBrainImage,9);
imshow(BBrainImage)
end

댓글을 달려면 로그인하십시오.

채택된 답변

GandaBerunda
GandaBerunda 2022년 7월 8일
Hi Alexandr,
ones() returns an array or a matrix all the elements of which are the number 1. In your case, it will return a 91x109 int8 array all of whose elements are 1, which will be stored in BrainImage.

추가 답변 (1개)

Image Analyst
Image Analyst 2022년 7월 9일
If you don't, and you just do
BrainImage(:,:) = aalAtlas.tissue(:, :, 50)
then, since ":" means "all" it will try to take the 50th slice and put it into BrainImage. The problem is that since you used : it means 1:end but it doesn't know the size of BrainImage yet so it throws an error with that syntax. It would have worked if you just didn't try to reference any row and column range, like this:
BrainImage = aalAtlas.tissue(:, :, 50)

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by