Creating a new array that contains number of overlap of non-zero values

5 次查看(过去 30 天)
I have 4 equally sized arrays (under ARV.HEMEsubt_otsu), and the 'ARV' structure is attached with this question. I'm trying to create an array of equal size (105 x 107 double) that shows the total of the other arrays have non-zero values (i.e. 0, 1, 2, 3, or all 4). So for instance, at the row 75, column 57 cell location, only mz316 has a non-zero value so the new array would have a 1 in that cell in the new array.
I surmise a for loop that goes through the entire array and then assessing the others' cell values, but does anyone have any thoughts?
Happy to provide additional clarification as needed. Thanks!

采纳的回答

Image Analyst
Image Analyst 2021-11-28
编辑:Image Analyst 2021-11-28
Zeros add to zero, so why don't just add up those 4 arrays:
s=load('Arrays_11282021.mat')
s1 = s.ARV.HEMEsubt_otsu
m = s1.mz248 + ...
s1.mz288 + ...
s1.mz316 + ...
s1.mz445
imshow(m, [], 'InitialMagnification', 1600);
axis('on', 'image')
If you don't want the values themselves added, but just add 1 regardless ofthe value in there, just threshold at zero before adding:
s=load('Arrays_11282021.mat')
s1 = s.ARV.HEMEsubt_otsu
m = s1.mz248 > 0 + ...
s1.mz288 > 0 + ...
s1.mz316 > 0 + ...
s1.mz445 > 0
imshow(m, [], 'InitialMagnification', 1600);
axis('on', 'image')
  2 个评论
Aaron Devanathan
Aaron Devanathan 2021-11-29
Thanks @Image Analyst! I'll accept the answer. I'm curious: is there a way to display the image so that each number greater than 0 is its own color in the final array 'm'? Sorry if that's beyond the scope fo the question.
Image Analyst
Image Analyst 2021-11-29
Try this:
s = load('Arrays_11282021.mat')
s1 = s.ARV.HEMEsubt_otsu
m = uint8(s1.mz248 > 0) + ...
uint8(s1.mz288 > 0) + ...
uint8(s1.mz316 > 0) + ...
uint8(s1.mz445 > 0);
imshow(m, [], 'InitialMagnification', 1600);
axis('on', 'image')
impixelinfo; % Show (x,y) and value
colormap(lines(5))
colorbar

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by