Azzera filtri
Azzera filtri

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

1 visualizzazione (ultimi 30 giorni)
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 Commento
Walter Roberson
Walter Roberson il 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')

Accedi per commentare.

Risposta accettata

Voss
Voss il 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 Commenti
Matt J
Matt J il 24 Feb 2024
Modificato: Matt J il 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 il 24 Feb 2024
Modificato: Voss il 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.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Elementary Polygons in Help Center e File Exchange

Prodotti


Release

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by