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

3 views (last 30 days)
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 Comment
Walter Roberson
Walter Roberson on 24 Feb 2024
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')

Sign in to comment.

Accepted Answer

Voss
Voss on 24 Feb 2024
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 Comments
Matt J
Matt J on 24 Feb 2024
Edited: Matt J on 24 Feb 2024
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 on 24 Feb 2024
Edited: Voss on 24 Feb 2024
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.

Sign in to comment.

More Answers (0)

Categories

Find more on Elementary Polygons in Help Center and File Exchange

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!