File Exchange

image thumbnail

Magic kernel resizing

version 1.2 (2.27 KB) by

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

4 Downloads

Updated

View License

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/

Comments and Ratings (9)

sara

sara (view profile)

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.

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.

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;

bmv

bmv (view profile)

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

bmv

bmv (view profile)

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

Anton Semechko

Anton Semechko (view profile)

The cambridgeincolour link is pretty awesome. Thanks!

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.

Anton Semechko

Anton Semechko (view profile)

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

Updates

1.2

Fixed typo in the illustration image.

1.1

Typo.

MATLAB Release
MATLAB 6.5 (R13)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video