Why figure doesn't render properly? (Opengl painters)

5 ビュー (過去 30 日間)
Simone Cotta Ramusino
Simone Cotta Ramusino 2022 年 10 月 13 日
I was trying to save a uint8 3D RGB matrix into png format with print(), but some pixels showed undesired shades. First try, I was saving a simple magenta rectangle (matrix 300x600x3) and the shades were on the borders: I solved setting the renderer to 'painters' (figures attached)
But when I tried the same on a much larger matrix (945x2556x4355) with more complex plot, even '-painters' does not work
Maybe here is not very clear, but in the original output I just want white and magenta pixels, while you can see here there are a lot of pink and grey shades that (I checked it) are not present in the original matrix and they don't show up when I display the image with imshow(). It's a matter of how Matlab represent the output.
I've read that Matlab can't mantain 'painters' for complex plot and adjust automatically the renderer to Opengl, so I tried to force it with several solutions:
imshow(layer1) % my matrix
s=1
fig=get(groot,'CurrentFigure');
fig.PaperUnits='points';
fig.PaperPosition=[0 0 288 144]; % I need a 600x300 pixel output
fig.Renderer='painters';
fig.RendererMode='manual';
filenamearray=["layer",s];
loopfilename=strjoin(filenamearray,'_');
axis off;
print('-painters','-dpng',loopfilename);
%%% or
print('-painters',loopfilename,"-dpng");
%%% or
print('-vector',loopfilename,"-dpng");
%%% or
print('-zbuffer',loopfilename,"-dpng");
%%% or
saveas(fig,"layer1",'png');
but they work only for the simple rectangle.
Any hint? Thanks in advance
  8 件のコメント
Simone Cotta Ramusino
Simone Cotta Ramusino 2022 年 10 月 14 日
brick=zeros(300,600,3,'uint8');
brick(:,:,1)=165;
brick(:,:,2)=35;
brick(:,:,3)=99;
imshow(brick)
loops=100
for index=1:loops
filenamearray=["face",index];
loopfilename=strjoin(filenamearray,'_');
imshow(brick);
fig=get(groot,'CurrentFigure');
fig.PaperUnits='points';
fig.PaperPosition=[0 0 288 144]; %
axis off;
print('-painters',loopfilename,"-dpng");
end
This is how I create the little magenta block (with 'painters' specified I have no shade, as you will see). The second image is obtained in the same way, but, instead of a single whole color, there are two colors assigned randomly to some elements of the matrix and some black background. It would be complex to reproduce the whole code, but you can simply recreate it with randi/rand or just assigning some pixels. Let me know if you achieve anything or not. Your help is aprreciated.
Regards

サインインしてコメントする。

回答 (2 件)

Robert U
Robert U 2022 年 10 月 14 日
Hi Simone Cotta Ramusion,
as suspected I could reproduce the smoothing at the edges. Setting smoothing off, eliminates the shaded starting and ending pixels in each line. Even I use the default renderer.
brick=zeros(300,600,3,'uint8');
brick(:,:,1)=165;
brick(:,:,2)=35;
brick(:,:,3)=99;
imshow(brick)
loops=1;
for index=1:loops
filenamearray=["face",index];
loopfilename=strjoin(filenamearray,'_');
imshow(brick);
fig=get(groot,'CurrentFigure');
fig.PaperUnits='points';
fig.PaperPosition=[0 0 288 144]; %
fig.GraphicsSmoothing = 'off';
axis off;
print(loopfilename,"-dpng");
end
  16 件のコメント
Simone Cotta Ramusino
Simone Cotta Ramusino 2022 年 10 月 21 日
Dear Robert,
thank you very much for your efforts. In the end, I think I will go for 'imwrite', even if it is not what I really wanted at the beginning. There are probably some rendering settings that I could not handle.
Thanks again
Best

サインインしてコメントする。


Simone Cotta Ramusino
Simone Cotta Ramusino 2022 年 10 月 19 日
Sorry for insisting again, can I ask (@Robert U, @Jan or anyone else who does not have this problem in the output) if you can attacched your export setup settings, from the figure menu? Because I think that there may be the solution.
I am really sorry to disturb you again, but this is very important

カテゴリ

Find more on Graphics Performance in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by