Code covered by the BSD License  

Highlights from
Magic kernel resizing

Be the first to rate this file! 11 Downloads (last 30 days) File Size: 2.27 KB File ID: #40392
image thumbnail

Magic kernel resizing

by

 

19 Feb 2013 (Updated )

The “magic kernel” is a method of resampling images that gives clear results free of artifacts.

| Watch this File

File Information
Description

The “magic kernel” is a method of resampling images that gives amazingly clear results (free of “aliasing” artifacts, free of “ringing”, and free of “width beat” for thin features) yet is lightning fast (the simplest version only requires a few integer additions and bit-shifts).

The full method description is available at http://johncostella.webs.com/magic/

Required Products Image Processing Toolbox
MATLAB release MATLAB 6.5 (R13)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (8)
22 Oct 2013 drdrb

% Also use this:

output = double(output(...
2:2:end-1,2:2:end-1));

% instead of this:

[height,width]=size(image);
height2=ceil(height/2);
width2=ceil(width/2);
height2l=floor(height/2);
width2l=floor(width/2);
matrix1=spalloc(height2,height,height2);
for j=1:height2l
matrix1(j,j*2)=1;
end
matrix2=spalloc(width,width2,width2);
for j=1:width2l
matrix2(j*2,j)=1;
end
output=matrix1*double(output)* matrix2;
output=output(1:end-1,1:end-1);

%sparse matrices are fancy, but just %avoiding "for" at any price(even %readability) can get you farther.

22 Oct 2013 drdrb

% Also use this:

output = double(output(...
2:2:end-1,2:2:end-1));

% istaid of this:

[height,width]=size(image);
height2=ceil(height/2);
width2=ceil(width/2);
height2l=floor(height/2);
width2l=floor(width/2);
matrix1=spalloc(height2,height,height2);
for j=1:height2l
matrix1(j,j*2)=1;
end
matrix2=spalloc(width,width2,width2);
for j=1:width2l
matrix2(j*2,j)=1;
end
output=matrix1*double(output)* matrix2;
output=output(1:end-1,1:end-1);

%sparse matrices are fancy, but just %avoiding "for" at any price(even %readability) can get you farther.

22 Oct 2013 drdrb

% Thank you!
% It's just what I was searching for!
% Great piece of code
% Just to note that this:

output=zeros(2*size(image));
output(2:2:end,2:2:end)=image;

% is much faster then this:

[height,width]=size(image);
matrix1=spalloc(2*height,height,height);
for i=1:height
matrix1(2*i,i)=1;%#ok
end
matrix2=spalloc(width,2*width,width);
for i=1:width
matrix2(i,2*i)=1;%#ok
end
output=matrix1*double(image)*matrix2;

02 Apr 2013 bmv

I mean : B=magickernel(magickernel(A),'DOWN');

02 Apr 2013 bmv

After these transformations:
A;
B=magickernel(magickernel(A),'DAWN');
Should A and B be the same? (A=B ?)

25 Feb 2013 Anton Semechko

The cambridgeincolour link is pretty awesome. Thanks!

24 Feb 2013 Jan Motl

It's a trade-off. Either you can have sharp images with halos (that's the case of bicubic interpolation) or blurred images without halos (like with Magic kernel).

More details about the interpolation trade-off are available at http://www.cambridgeincolour.com/tutorials/digital-photo-enlargement.htm

The artifacts particularly present in bicubic interpolation are described, for example, at Wikipedia: https://en.wikipedia.org/wiki/Bicubic_interpolation#Use_in_computer_graphics

Magic kernel is useful if you need extreme blow-ups or if you further post process the image and the used algorithm is sensitive to artifacts introduced by interpolation.

19 Feb 2013 Anton Semechko

So what are the artifacts that are present in the image interpolated with a cubic spline?

Updates
25 Feb 2013

Typo.

01 Apr 2013

Fixed typo in the illustration image.

Contact us