4.82353

4.8 | 17 ratings Rate this file 174 downloads (last 30 days) File Size: 268.24 KB File ID: #20979

Myaa - My Anti-Alias for Matlab

by Anders Brun

 

05 Aug 2008 (Updated 21 Aug 2008)

Code covered by BSD License  

Better looking Matlab figures with anti-aliasing!

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

Download Now | Watch this File

File Information
Description

Add myaa.m to your path and enjoy anti-aliased professionally looking graphics in Matlab at any time. Myaa works with any kind of graphic (3-D, plots, scatterplots, ...) and even adds anti-aliasing to text, ui controls and grids. Myaa is ideal for complex, cluttered and saturated plots.

See attached screenshot for a demonstration. More examples included in the code, just run 'help myaa'.

Curiosa:
For those of you who 'publish' your code often, an undocumented anti-aliasing option is included in the snapnow.m function in Matlab. To publish a file called test.m you can do:

opts.figureSnapMethod = 'antialiased';
publish('test.m',opts)

However, you will have more control over the process using myaa, which is also the best choice when using Matlab interactively.

In any case: Anti-aliasing is good for you! :-)

Acknowledgements
This submission has inspired the following:
print2im, export_fig
MATLAB release MATLAB 7.6 (R2008a)
Zip File Content  
Other Files license.txt,
myaa/copying,
myaa/copyright,
myaa/myaa.m,
myaa/screenshot.jpg,
myaa/screenshot.png
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (25)
05 Aug 2008 Petr Krysl

Well done! Just a small suggestion for improvement: ippl() was not found by Matlab (probably because I do not have the image processing toolbox). This should be perhaps treated with a try, catch?

I have not looked at the code in detail, hence no rating yet.

06 Aug 2008 i scardanzan

rating based on the posted visualization

06 Aug 2008 Anders Brun

Thanks for the suggestion Petr. I have submitted a new version now, including a small change for this:

try
    if ippl()
        myconv = @imfilter;
        mypad = 'same';
    else
        myconv = @conv2;
        mypad = 'valid';
    end
catch
    myconv = @conv2;
    mypad = 'valid';
end

06 Aug 2008 Anders Brun

For your information, every resubmission takes some time to propagate through Mathworks review process... so if you have problems related to the ippl() function, please implement the bugfix below. The new version should be available for download in about a day or so.

Thank you for your patience. /Anders

07 Aug 2008 Peter A.

Works great, thanks!

12 Aug 2008 Per Magnusson

myaa works great and is very easy to use. Thanks Anders!

19 Aug 2008 Andrey Krishkevich

Beautiful!

26 Aug 2008 Matt S  
02 Sep 2008 Nass K

It works fine, thanks.

03 Sep 2008 Adam Chapman

Excellent job. Thanks very much!

04 Sep 2008 Husam Aldahiyat  
11 Sep 2008 Liu Michael

Very good, wonderful...

12 Sep 2008 Stefan Novak

Excellent job! Looking forward to future releases and features!

21 Oct 2008 Luc Masset

Fantastic. Great work. I have been looking for an anti-aliasing feature in Matlab for years.

I've just changed two small things to have myaa to work in Matlab R13 :

line 111: remove the (), I guess it always takes @conv2

line 213: I changed this way :

    raw_lowres = double(imresize(self.raw_hires,1/self.K(2),'bilinear'))/256;
    raw_lowres = single(raw_lowres);

Thanks again Anders.

08 Nov 2008 matt dash  
08 Nov 2008 matt dash

very nice, but i think it should optionally take a figure handle as an input instead of just using gcf.

14 Nov 2008 Oliver Woodford

A nice idea that has greatly improved some figures I'm publishing.

I would have liked the function to simply save the anti-aliased output to file (png). I've now written something similar which does just that.

12 Dec 2008 Sebastian Hölz

I hate to tell you, but your file is of very limited use. Little known fact: Matlab (at least from 7.04 on) includes an AA, it is just hidden. Try the following:
>> spharm2
>> set(gco,'LineSmoothing','on')
It will give you AA on the real 3D object, i.e. paning, rotating, zooming possible in real-time, no need for time- and memory-consuming calculations. The "LineSmoothing"-property is available for all relevant HGObjects, i.e. lines, patches, surfaces.
I think the smoothing is also applied to exported and saved figures, as long as you specify ZBuffer or OpenGL as renderer.

Sebastian

12 Dec 2008 Anders Brun

Hi Sebastian,
I already know of LineSmoothing and I created Myaa because I needed something more general. LineSmoothing does exactly what is says, it can smooth a line. If two lines crosses, things start go wrong. And there are more relevant objects in Matlab, such as text labels and (unintentionally) hires images, say a 3000x3000 image. Myaa will show you what your figure will look like in print, LineSmoothing will not. But ofcourse LineSmoothing is useful to some people and in some situations, speed is one of its advantages but generality is not.

Believe me, nobody would be more happy than me the day Matlab can do true antialiasing in hardware. :-)

04 Jun 2009 Nitika

Anders, Could you use this while making a movie (say with getframe)? I havent tried it yet, but it looks like - if you can, it will probably take infinite time to do that...
Nevertheless, this is a beautiful application! Thanks!

24 Jun 2009 Morag  
10 Jul 2009 JD  
10 Jul 2009 cartonn  
14 Jul 2009 cartonn

great submission! How do you set a high super-sampling factor, a low down-sampling factor, and still get the full image? When I do those, myaa automatically zooms in and I only get some portion of the image..

27 Aug 2009 Linda F  
Please login to add a comment or rating.
Updates
06 Aug 2008

Fixed a bug for people not having the image processing toolbox...

21 Aug 2008

Added interactivity to the user interface and cleaned up some of the code.

21 Aug 2008

Found bugs in last night update. The interactive zoom is now somewhat more stable... Enjoy.

21 Aug 2008

Again, some minor bugs... sorry.

21 Aug 2008

Changed some nomenclature in the code. Thanks to Khalid.

Tag Activity for this File
Tag Applied By Date/Time
annotation Anders Brun 22 Oct 2008 10:13:22
customization Anders Brun 22 Oct 2008 10:13:22
antialiasing Anders Brun 22 Oct 2008 10:13:22
smooth Anders Brun 22 Oct 2008 10:13:22
html Anders Brun 22 Oct 2008 10:13:22
jpg Anders Brun 22 Oct 2008 10:13:22
presentation Anders Brun 22 Oct 2008 10:13:22
png Anders Brun 22 Oct 2008 10:13:22
raster Anders Brun 27 Oct 2008 16:58:23
myaa Anders Brun 31 Oct 2008 13:33:04
potw Cristina McIntire 07 Nov 2008 13:05:43
antialiasing Menl 26 Feb 2009 05:18:28
antialiasing Mike 28 Jul 2009 15:12:27
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com