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

조회 수: 3 (최근 30일)
Matt J
Matt J 2024년 2월 24일
편집: Voss 2024년 2월 24일
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