Why don't getframe RGB codes agree with plotted polyshape RGB codes?

1 次查看(过去 30 天)
In the code below, I have computed the RGB color code of the square as seen in both a polyshape plot (polyshapeRGB) and as seen by a getframe() capture of this plot (getframeRGB). Why are the two not in agreement, and is there a way either to make them agree or to predict one version of the RGB values from the other?
h=plot(nsidedpoly(4));
I=getframe;
ctr=round(size(I.cdata,1:2)/2);
polyshapeRGB=round(255*h.FaceColor)
polyshapeRGB = 1×3
0 114 189
getframeRGB(1:3)=I.cdata( ctr(1), ctr(2),:)
getframeRGB = 1×3
166 205 231
  1 个评论
Walter Roberson
Walter Roberson 2024-2-24
h=plot(nsidedpoly(4));
I=getframe;
ctr=round(size(I.cdata,1:2)/2);
polyshapeRGB=round(255*h.FaceColor)
polyshapeRGB = 1×3
0 114 189
getframeRGB(1:3)=I.cdata( ctr(1), ctr(2),:)
getframeRGB = 1×3
166 205 231
figure
polyshapeRGB = reshape(uint8(polyshapeRGB), 1, 1, 3);
image(repmat(polyshapeRGB, 64, 64, 1));
title('polyshape swath')
figure
getframeRGB = reshape(uint8(getframeRGB), 1, 1, 3);
image(repmat(getframeRGB, 64, 64, 1));
title('getframe swath')

请先登录,再进行评论。

采纳的回答

Voss
Voss 2024-2-24
They don't agree because of the transparency of the polyshape.
Default FaceAlpha=0.35:
figure
h=plot(nsidedpoly(4)); % default FaceAlpha=0.35
I=getframe();
ctr=round(size(I.cdata,1:2)/2);
polyshapeRGB=round(255*h.FaceColor)
polyshapeRGB = 1x3
0 114 189
getframeRGB(1:3)=I.cdata( ctr(1), ctr(2),:)
getframeRGB = 1x3
166 205 231
FaceAlpha=1, fully opaque:
figure
h=plot(nsidedpoly(4),'FaceAlpha',1); % fully opaque
I=getframe();
ctr=round(size(I.cdata,1:2)/2);
polyshapeRGB=round(255*h.FaceColor)
polyshapeRGB = 1x3
0 114 189
getframeRGB(1:3)=I.cdata( ctr(1), ctr(2),:)
getframeRGB = 1x3
0 114 189
  2 个评论
Matt J
Matt J 2024-2-24
编辑:Matt J 2024-2-24
Yes, I see that now, thanks. But how is the alpha-blending done? Is it always a linear blending?
It seems to be in this case,
alpha=0.35;
predictedRGB = round( [0 114 189]*alpha + 255*(1-alpha) )
predictedRGB = 1×3
166 206 232
Voss
Voss 2024-2-24
编辑:Voss 2024-2-24
Seems linear in that case, yeah. Another case where it seems linear:
figure
h=plot(nsidedpoly(4)); % default FaceAlpha=0.35
alpha = h.FaceAlpha;
polycolor = h.FaceColor*255;
axescolor = [255 120 50];
set(gca(),'Color',axescolor/255);
I=getframe();
ctr=round(size(I.cdata,1:2)/2);
getframeRGB(1:3)=I.cdata( ctr(1), ctr(2),:)
getframeRGB = 1x3
166 117 98
predictedRGB = round( polycolor*alpha + axescolor*(1-alpha) )
predictedRGB = 1x3
166 118 99
So I think always linear would be a reasonable guess.

请先登录,再进行评论。

更多回答(0 个)

类别

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

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by