Code covered by the BSD License  

Highlights from
Magic kernel resizing

5.0
5.0 | 1 rating Rate this file 13 Downloads (last 30 days) File Size: 2.27 KB File ID: #40392 Version: 1.2
image thumbnail

Magic kernel resizing

by

Jan Motl (view profile)

 

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 (9)
15 Jan 2015 sara

sara (view profile)

 
22 Oct 2013 drdrb

drdrb (view profile)

% 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.

Comment only
22 Oct 2013 drdrb

drdrb (view profile)

% 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.

Comment only
22 Oct 2013 drdrb

drdrb (view profile)

% 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;

Comment only
02 Apr 2013 bmv

bmv (view profile)

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

Comment only
02 Apr 2013 bmv

bmv (view profile)

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

Comment only
25 Feb 2013 Anton Semechko

The cambridgeincolour link is pretty awesome. Thanks!

Comment only
24 Feb 2013 Jan Motl

Jan Motl (view profile)

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.

Comment only
19 Feb 2013 Anton Semechko

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

Comment only
Updates
25 Feb 2013 1.1

Typo.

01 Apr 2013 1.2

Fixed typo in the illustration image.

Contact us