Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
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 Kommentar
Walter Roberson
Walter Roberson am 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')

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Voss
Voss am 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 Kommentare
Matt J
Matt J am 24 Feb. 2024
Bearbeitet: Matt J am 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 am 24 Feb. 2024
Bearbeitet: Voss am 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Elementary Polygons finden Sie in Help Center und File Exchange

Produkte


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by