When I set transparency in the figure, the original smooth line becomes nonsmooth.
[x,y] = meshgrid(-2:.2:2);
z = x.*exp(-x.^2-y.^2);
a = gradient(z);
figure; surf(x,y,z,'AlphaData',a,'FaceAlpha','flat','FaceColor','blue');
figure; surf(x,y,z)

댓글 수: 2

KALYAN ACHARJYA
KALYAN ACHARJYA 2018년 7월 26일
What is your question?
bai da
bai da 2018년 7월 26일
Jan has pointed out the problem. The line becomes nonsmooth after I set transparency to the figure

댓글을 달려면 로그인하십시오.

 채택된 답변

Jan
Jan 2018년 7월 26일

0 개 추천

Transparency requires the OpenGL renderer. The line-smoothing requires the Painters renderer. As far as I can see, you observe the expected behavior.

댓글 수: 5

bai da
bai da 2018년 7월 26일
Thanks! Are there any trick to avoid this dilemma?
Jan
Jan 2018년 7월 26일
편집: Jan 2018년 7월 26일
"Dilemma" means that it is not a "lemma", or in other words: It cannot be decided. This implies, that you cannot avoid it, because it is the nature of the different renderers.
But you can reduce the effects or find a work-around. It depends on what you want to do with the displayed graphics. Does your problem concerns the output to the screen or do you want to export a smoothed graphics file? KALYAN ACHARJYA asked already, what your question is.
Which Matlab version are you using and do you have the Image Processing toolbox?
bai da
bai da 2018년 7월 26일
Yes, I want to export a smoothed file. I'm using version 2017a. I have the image processing toolbox
Jan
Jan 2018년 7월 26일
편집: Jan 2018년 7월 26일
Try this:
RGB = AntiAlias(gcf, 4, 'lanczos3');
imwrite(RGB, 'File.png');
Using this function:
function Out = AntiAlias(FigH, K, Method)
% Anti-aliasing of a figure
% Reply = AntiAliasFig(FigH, K)
% FigH: Figure handle.
% K: Integer subsampling factor >= 1: The created pictures uses a K-times
% higher resolution.
% For K = 1 the output equals the original picture.
% Method: See Method of IMRESIZE: E.g. 'lanczos3'
%
% OUTPUT:
% Reply: RGB data are replied as [M x N x 3] UINT8 array.
%
% Tested: Matlab/64 9.1, Win10
% Author: Jan Simon, Heidelberg, (C) 2018
% Initialize: ==================================================================
screen_DPI = get(groot, 'ScreenPixelsPerInch');
% Do the work: =================================================================
% Wanted resolution as string:
ResolutionStr = sprintf('-r%d', round(screen_DPI * K));
% Prepare figure for hardcopy:
drawnow;
fig_Renderer = get(FigH, 'Renderer');
fig_Paperposmode = get(FigH, 'PaperPositionMode');
fig_PaperOrient = get(FigH, 'PaperOrientation');
fig_Invhardcopy = get(FigH, 'InvertHardcopy');
set(FigH, ...
'PaperPositionMode', 'auto', ...
'PaperOrientation', 'portrait', ...
'InvertHardcopy', 'off');
% Create hard copy in high resolution: -----------------------------------------
% Simulate PRINT command (save time for writing and reading image file):
% Set units of axes and text from PIXELS to POINTS to keep their sizes
% independent from from the output resolution:
% See: graphics/private/preparehg.m
root_SHH = get(groot, 'ShowHiddenHandles');
set(groot, 'ShowHiddenHandles', 'on');
text_axes_H = [findobj(FigH, 'Type', 'axes'); ...
findobj(FigH, 'Type', 'text')];
pixelObj = findobj(text_axes_H, 'Units', 'pixels');
fontPixelObj = findobj(text_axes_H, 'FontUnits', 'pixels');
set(pixelObj, 'Units', 'points');
set(fontPixelObj, 'FontUnits', 'points');
fig_ResizeFcn = get(FigH, 'ResizeFcn');
set(FigH, 'ResizeFcn', '');
% Get image as RGB array:
high = print('-RGBImage', ResolutionStr);
% Restore units of axes and text objects, and EraseMode:
set(pixelObj, 'Units', 'pixels');
set(fontPixelObj, 'FontUnits', 'pixels');
set(groot, 'ShowHiddenHandles', root_SHH);
set(FigH, 'ResizeFcn', fig_ResizeFcn);
% Restore properties of the original image:
set(FigH, ...
'InvertHardcopy', fig_Invhardcopy, ...
'PaperPositionMode', fig_Paperposmode, ...
'PaperOrientation', fig_PaperOrient, ...
'Renderer', fig_Renderer);
% Create the low resolution data and axes properties:
try
low = imresize(high, 1 / K, Method); % Hide from CheckSyntax
catch ME
if isempty(which('imresize'))
error(['*** %s: Signal-Processing-Toolbox is required.', ...
char(10), '%s'], mfilename, Mode, ME.message);
else
error(['*** %s: Unknown [Mode]: [%s]', ...
char(10), '%s'], mfilename, Mode, ME.message);
end
end
% Limit range of data:
% Slightly slower: lowres = max(min(lowres, 1), 0);
if isa(low, 'double')
low(low < 0) = 0;
low(low > 1) = 1;
end
Out = low;
end
bai da
bai da 2018년 7월 30일
편집: bai da 2018년 7월 30일
Thank you very much! It works! It also works in Linux (Ubuntu).

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Indrajit Wadgaonkar
Indrajit Wadgaonkar 2021년 8월 10일
편집: Indrajit Wadgaonkar 2021년 8월 10일

0 개 추천

Did this issue get resolved? What is the solution if I need transparency as well as smooth lines?

카테고리

도움말 센터File Exchange에서 Spline Postprocessing에 대해 자세히 알아보기

태그

질문:

2018년 7월 26일

편집:

2021년 8월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by