이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
Why figure doesn't render properly? (Opengl painters)
조회 수: 7 (최근 30일)
이전 댓글 표시
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
Jan
2022년 10월 13일
Did you update the drivers of your graphics card? Which Matlab version are you using? The last version, which supported "ZBuffer" was R2014a.
Simone Cotta Ramusino
2022년 10월 13일
How can I update them and in which way do they affect the output?
I am using R2021B. I tried zbuffer just to try everything, but I am quite sure that the solution must be within 'painters'. I don't know if there are other figure options that can avoid this "antialiasing" effect
Simone Cotta Ramusino
2022년 10월 13일
Ok, I have checked the driver and they are already updated. According to you, can I try something else?
Robert U
2022년 10월 14일
Check, whether you deactivated the default-graphics improvements such as smoothing: https://de.mathworks.com/help/matlab/ref/rendererinfo.html?searchHighlight=painters&s_tid=srchtitle_painters_4
Additionally, I am not sure, whether or not the resolution and dpi values are forced correctly. Have a look here: https://de.mathworks.com/matlabcentral/answers/415952-plot-resolution-and-size?s_tid=srchtitle
Kind regards,
Robert
Simone Cotta Ramusino
2022년 10월 14일
Dear Robert, thanks for your answer. If I check the info with painter renderer, I get no meaningful details of default graphics, while opengl has all the graphics parameters set to 1. But I am not sure that's what I need, on the contrary I think that something like smoothing can be the problem. Anyway, I tried to run it again with opengl and SupportGraphicsSmoothing set to 0 and it still doesn't work properly.
Yes I am quite sure the resolution is set correctly.
Have you ever faced such a problem? I read everywhere and they usually solved it with painters renderer..unfortunately, that's not the case..
Simone Cotta Ramusino
2022년 10월 14일
Do you think it would be more helpful a hardware accelerated (that has already Smoothing set to 0) or software graphics?
Robert U
2022년 10월 14일
Can you provide some data you are working with. Then, it would be possible to reconstruct your problem maybe, and try to fix it.
Kind regards,
Robert
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
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
2022년 10월 14일
Yeah I know that it can be solved for this little "brick": It is the larger and multicolor matrix that keeps giving troubles, and I have already tried with GraphicsSmoothing='off', with no results. If you cannot reproduce it by yourself I will try to attach something here, but I think you can simply try to print multicolor random pixels on a black background.
Thanks again
Simone Cotta Ramusino
2022년 10월 14일
If you creat the block like this, you can see that there is a minimal pink shade, that does not disappear even with 'painters' o GraphicsSmoothing='off'
brick=zeros(1300,1600,3,'uint8');
brick(:,:,1)=165;
brick(1160:1170,2:500,1)=255;
brick(:,:,2)=35;
brick(1160:1170,2:500,2)=255;
brick(:,:,3)=99;
brick(1160:1170,2:500,3)=255;
imshow(brick)
Simone Cotta Ramusino
2022년 10월 15일
I fixed the code so that it's even more evident the difference between the Matlab visualization (the imshow output) and the saved results (the print output)
brick=zeros(1300,1600,3,'uint8');
colonnebianche=randi(1550,[500,1]);
righebianche=randi(1000,[400,1]);
brick(:,:,1)=165;
brick(righebianche,colonnebianche,1)=255;
brick(:,:,2)=35;
brick(righebianche,colonnebianche,2)=255;
brick(:,:,3)=99;
brick(righebianche,colonnebianche,3)=255;
imshow(brick)
Robert U
2022년 10월 17일
Hi Simone Cotta Ramusino,
I tried to reproduce the problem with your test image. Unfortunately, I do not see any minimal pink shade. Maybe, you can attach a file with the region of interest.
brick=zeros(1300,1600,3,'uint8');
colonnebianche=randi(1550,[500,1]);
righebianche=randi(1000,[400,1]);
brick(:,:,1)=165;
brick(righebianche,colonnebianche,1)=255;
brick(:,:,2)=35;
brick(righebianche,colonnebianche,2)=255;
brick(:,:,3)=99;
brick(righebianche,colonnebianche,3)=255;
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

Kind regards,
Robert
Simone Cotta Ramusino
2022년 10월 17일
Hi Robert,
are you sure there are no pink shades? Because I can almost see them without zooming in on the image. Did you try to save the print output and to open it with, for example, Paint3D and use the color picker? You will see that the white are not really white, but composed of, more or less, pink, red and rose pixels.
This is my (zoomed) Matlab output with imshow:

You can see that the white dots are clearly, purely and only white. Instead, if you consider the (zoomed) image saved with print:

you can see that the white areas are not perfectly white, you can check it with colorpicker.
Please try again magnifing your output and you will see what I am talking about. If not, then probably you have different image rendering settings that I would like to know (I have R2021b version).
Thanks again for your support
Robert U
2022년 10월 17일
Hi Simone Cotta Ramusino,
I attached the saved file which I got with the code posted in the comment above with your example data. I ran it in R2021b.

When magnifying, I cannot see any shades. Looks ok to me.

Kind regards,
Robert
Simone Cotta Ramusino
2022년 10월 17일
Ohh how's that possible? :(
How strange..did you see any particular options in your export settings? I just can't figure it out..because in the first one you posted the shades are visible. Did you change anything else?
Moreover, could you possibily try it even on R2022b version?
Kind regards
Simone Cotta Ramusino
2022년 10월 17일
Ok, don't ask me why, but now, if I reproduce the code without 'painters' option in the print function, it seems ok! I will try on the more complex data and I'll let you know. I don't really get what can be the difference
Robert U
2022년 10월 17일
Hi Simone Cotta Ramusino,
as written above, I only changed the smoothing on and off with that particular line:
fig.GraphicsSmoothing = 'off';
I did not change anything else. I did not use '-painters' renderer in comparison to your initial post.
Unfortunately, I cannot run the example in R2022b. Sorry.
Kind regards,
Robert
Simone Cotta Ramusino
2022년 10월 17일
No way, it keeps giving me error. I found that, for the magenta brick, the solution is not GraphicsSmoothing (which I can remove), but setting: opengl hardware. But I do the same for the other data, it does not work
What is your opengl settings?
Best regards
Robert U
2022년 10월 17일
opengl info
Version: '4.6.0 NVIDIA 472.98'
Vendor: 'NVIDIA Corporation'
Renderer: 'Quadro P2000/PCIe/SSE2'
RendererDriverVersion: '30.0.14.7298'
RendererDriverReleaseDate: '05-Jan-2022'
MaxTextureSize: 32768
Visual: 'Visual 0x09, (RGBA 32 bits (8 8 8 8), Z depth 16 bits, Hardware acceleration, Double buffer, Antialias 8 samples)'
Software: 'false'
HardwareSupportLevel: 'full'
SupportsGraphicsSmoothing: 1
SupportsDepthPeelTransparency: 1
SupportsAlignVertexCenters: 1
Extensions: {394×1 cell}
MaxFrameBufferSize: 32768
Simone Cotta Ramusino
2022년 10월 17일
Same as me, more or less...
Version: '4.6.0 NVIDIA 516.40'
Vendor: 'NVIDIA Corporation'
Renderer: 'NVIDIA RTX A4000/PCIe/SSE2'
MaxTextureSize: 32768
Visual: 'Visual 0x09, (RGBA 32 bits (8 8 8 8), Z depth 16 bits, Hardware acceleration, Double buffer, Antialias 8 samples)'
Software: 'false'
HardwareSupportLevel: 'full'
SupportsGraphicsSmoothing: 1
SupportsDepthPeelTransparency: 1
SupportsAlignVertexCenters: 1
Extensions: {407×1 cell}
MaxFrameBufferSize: 32768
Thank you very much for your help, but it seems that this problem will remain unsolved..
Simone Cotta Ramusino
2022년 10월 18일
Hi Robert, sorry for bothering you again. If you can, would you check if the magenta brick output change if you put:
fig.GraphicsSmoothing="on"
or
opengl software
?
So we can see on what your output depends too. No obligations, obviously.
Thanks again
Best
Simone Cotta Ramusino
2022년 10월 19일
Moreover, if you try to still enlarge the figure, it will give you the same error. You can give it a try
brick=zeros(2300,2600,3,'uint8');
colonnebianche=randi(1550,[1000,1]);
righebianche=randi(1000,[400,1]);
brick(:,:,1)=165;
brick(righebianche,colonnebianche,1)=255;
brick(:,:,2)=35;
brick(righebianche,colonnebianche,2)=255;
brick(:,:,3)=99;
brick(righebianche,colonnebianche,3)=255;
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
Robert U
2022년 10월 21일
Hi Simone Cotta Ramusino,
I found another post here: https://de.mathworks.com/matlabcentral/answers/54750-getting-better-high-resolution-images leading to the website https://matlab.fandom.com/wiki/FAQ#How_do_I_save_my_figure,_axes,_or_image?_I'm_having_trouble_with_the_built_in_MATLAB_functions.
I tried https://github.com/altmany/export_fig but without changing settings I did not succeed to remove the artifacts in the bigger brick export. Maybe, investing more effort is necessary.
Kind regards,
Robert
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Graphics Performance에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)