简体   繁体   English

Matlab:AlphaData的警告尺寸必须与CData匹配

[英]Matlab: Warning Dimensions of AlphaData must match CData

The following code produces the error: 以下代码产生错误:

Warning: Dimensions of AlphaData must be 1x1, or must match CData. 警告:AlphaData的尺寸必须为1x1,或者必须与CData相匹配。

The problem is that CData is a color image and thus has 3 dimensions, and alphadata is a matrix of transparancy data abd thus has 2 dimensions. 问题在于CData是彩色图像,因此具有3个维度,而alphadata是透明数据abd的矩阵,因此具有2个维度。

red = cat(3, ones(512), zeros(512), zeros(512));
mask = [];
bounds = data(currow,1:6);
if slice >= bounds(5) && slice <= bounds(6)
    mask = zeros(size(segmask,1),size(segmask,2));
    mask(bounds(1)-4:bounds(2)+4,bounds(4)+4:bounds(4)+5) = 1;
    mask(bounds(2)+4:bounds(2)+5,bounds(3)-4:bounds(4)+4) = 1;
end
imshow(low(:,:,slice),[WL-WW/2 WL+WW/2])
hold on
h = imshow(red);
set(h, 'AlphaData', 0.3*mask);
hold off

Here is the info on AlphaData and CData from the Matlab Documentation 这是Matlab文档中有关AlphaData和CData的信息


AlphaData m-by-n matrix of double or uint8 double或uint8的AlphaData m×n矩阵

Transparency data. 透明度数据。 A matrix of non-NaN values specifying the transparency of each face or vertex of the object. 非NaN值的矩阵,指定对象的每个面或顶点的透明度。 The AlphaData can be of class double or uint8. AlphaData可以是double或uint8类。

MATLAB software determines the transparency in one of the following ways: MATLAB软件通过以下方式之一确定透明度:

Using the elements of AlphaData as transparency values (AlphaDataMapping set to none) 将AlphaData的元素用作透明度值(AlphaDataMapping设置为none)

Using the elements of AlphaData as indices into the current alphamap (AlphaDataMapping set to direct) 使用AlphaData的元素作为当前alphamap的索引(将AlphaDataMapping设置为direct)

Scaling the elements of AlphaData to range between the minimum and maximum values of the axes ALim property (AlphaDataMapping set to scaled, the default) 将AlphaData的元素缩放到介于轴ALim属性的最小值和最大值之间(AlphaDataMapping设置为scaled,这是默认值)


CData matrix | CData矩阵| m-by-n-by-3 array m×n×3阵列

The image data. 图像数据。 A matrix or 3-D array of values specifying the color of each rectangular area defining the image. 值的矩阵或3-D数组,用于指定定义图像的每个矩形区域的颜色。 image(C) assigns the values of C to CData. image(C)将C的值分配给CData。 MATLAB determines the coloring of the image in one of three ways: MATLAB通过以下三种方式之一确定图像的着色:

Using the elements of CData as indices into the current colormap (the default) (CDataMapping set to direct) 使用CData的元素作为当前颜色图的索引(默认)(将CDataMapping设置为direct)

Scaling the elements of CData to range between the values min(get(gca,'CLim')) and max(get(gca,'CLim')) (CDataMapping set to scaled) 将CData的元素缩放到介于min(get(gca,'CLim'))和max(get(gca,'CLim'))之间的范围内(CDataMapping设置为scaled)

Interpreting the elements of CData directly as RGB values (true color specification) 将CData的元素直接解释为RGB值(真彩色规范)

Note that the behavior of NaNs in image CData is not defined. 请注意,未定义图像CData中NaN的行为。 See the image AlphaData property for information on using transparency with images. 有关在图像上使用透明度的信息,请参见image AlphaData属性。


How Can AlphaData and CData possibly have the smae dimensions? AlphaData和CData如何可能具有smae尺寸?

In case red is 512x512x3 and mask is 512x512 and besides the warning the code seems to function as expected. 如果红色为512x512x3,掩码为512x512,则除了警告外,该代码似乎还可以正常工作。

I figured out my problem. 我发现了我的问题。 Because of the If statement the variable mask wasnt allays being created. 由于使用了If语句,因此无法创建可变mask

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM