Code Directory
 Visual Basic & VB.NET
New Code
Excel Add-in for DB2 1.7
wolfSSL 4.0.0
EntityDAC Express 2.2
SecureBridge 9.1
C# HTML to PDF 2019.6.5
PHP Ecommerce Script 3.6
Devart SSIS Data Flow Components 1.11
dbForge Data Compare for PostgreSQL 3.2.15
OrgChart JS 4.9.7
iScripts CyberMatch 1.3.3
AnyGantt JS Gantt Charts 8.7.0
Database Workbench Pro 5.6.8
SentiMask SDK Trial 2.0.193121
dbForge Studio for SQL Server 5.8
ODBC Driver for ASE 2.1.2
Top Code
SecureBridge 8.0
iScripts CyberMatch 1.3
dbForge Data Compare for PostgreSQL 2.0
dbForge Studio for SQL Server 5.5
Database Workbench Pro 5.6.8
PHP Ecommerce Script 1.0.4
Availability Booking Calendar PHP 1.0
ATN Site Builder 3.0
Excel Add-in for DB2 1.1
tkhtml 1.0
Windows Leaks Detector 1.1.3
TBG Engine Suite 2.0.6
MySpace Glitter Text Generator Module 1.0
myspace-events 0.1
myspace-ruby 0.7.1
Top Rated
VisualNEO Web 2018.12.15
Azizi search engine script PHP 4.1.10
Paste phpSoftPro 1.4.1
Extreme Injector 3.7
Deals and Discounts Website Script 1.0.2
ADO.NET Provider for ExactTarget 1.0
Solid File System OS edition 5.1
Classified Ad Lister 1.0
Aglowsoft SQL Query Tools 8.2
Invoice Manager by PHPJabbers 3.0
ICPennyBid Penny Auction Script 4.0
PHP Review Script 1.0
ATN Resume Finder 2.0
ATN Site Builder 3.0
Availability Booking Calendar PHP 1.0
Resampling volume or image with affine matrix 1.0
File ID: 86646

Resampling volume or image with affine matrix 1.0
Download Resampling volume or image with affine matrix 1.0http://www.mathworks.comReport Error Link
License: Shareware
File Size: 10.0 KB
Downloads: 7
Submit Rating:
Resampling volume or image with affine matrix 1.0 Description
Description: 3D Affine matrix is such a 4x4 matrix:

M = [ [R T]; [0 0 0 1] ];
[x2 y2 z2 1]d-deOao = M * [x1 y1 z1 1]d-deOao ;

where, R is a 3x3 rotation matrix, and T is a 3x1 translation matrix. [x1 y1 z1] is a location in original 3D image volume, and [x2 y2 z2] is a location in transformed 3D image volume.

Although affine geometric transformation is only limited to parallel projection, it applies to most of the common geometric transformations, including rotation, translation, scaling, reflection, shearing, etc. Some of the common 3D Affine matrices are listed at the bottom of this description.

It may seem easy if you just want to apply the 3D affine matrix to each [x y z] coordinates in the 3D image volume. However, it turns out to be more complicated when you realize that the voxel (smallest element of 3D image volume) in the transformed image may no longer be an orthogonal cube. Therefore, a 3D interpolation algorithms must also be included to transform 3D image volume. I have implemented three interpolation methods in this program.

Usage: [new_img new_M] = affine(old_img, old_M, [new_elem_size], [verbose], [bg], [method]);

old_img - original 2D image or 3D volume. We assume x for the 1st dimension, y for the 2nd dimension, and z for the 3rd dimension.

old_M - a 3x3 2D affine matrix for 2D image, or a 4x4 3D affine matrix for 3D volume. We assume x for the 1st dimension, y for the 2nd dimension, and z for the 3rd dimension.

new_elem_size (optional) - size of voxel along x y z direction for a transformed 3D volume, or size of pixel along x y for a transformed 2D image. We assume x for the 1st dimension y for the 2nd dimension, and z for the 3rd dimension. 'new_elem_size' is 1 if it is default or empty.

verbose (optional) - 1, 0
1: show transforming progress in percentage
2: progress will not be displayed
'verbose' is 1 if it is default or empty.

bg (optional) - background voxel intensity in any extra corner that is caused by 3D interpolation. 0 in most cases. 'bg' will be the average of two corner voxel intensities in original image volume, if it is default or empty.

method (optional) - 1, 2, or 3
1: for Trilinear interpolation
2: for Nearest Neighbor interpolation
3: for Fischer's Bresenham interpolation
'method' is 1 if it is default or empty.

I suggest that you should use Method 1 (Trilinear) unless you have good reasons to choose other methods. Method 2 (Nearest Neighbor) is slightly faster, but will bring larger interpolation error. The Method 3 (Fischer's Bresenham) is only an implementation to test the special algorithm, and you also need to download my 3D Bresenham's line generation program from:

new_img - transformed 3D image volume

new_M - transformed affine matrix

This program is inspired by:
SPM5 Software from Wellcome Trust Centre for Neuroimaging
Fischer, J., A. del Rio (2004). A Fast Method for Applying Rigid Transformations to Volume Data, WSCG2004 Conference.

Although this program (affine3d.m) can also run on MATLAB earlier than version 6.5 (R13), the speed will be hundred times slower. So I suggest that you run this program on MATLAB version 6.5 (R13) and above.

The following script is a demo to show you how to use this program. The result is displayed in the above image.

Example 1 (3D rotation):
load mri.mat; old_img = double(squeeze(D));
old_M = [0.88 0.5 3 -90; -0.5 0.88 3 -126; 0 0 2 -72; 0 0 0 1];
new_img = affine(old_img, old_M, 2);
[x y z] = meshgrid(1:128,1:128,1:27);
sz = size(new_img);
[x1 y1 z1] = meshgrid(1:sz(2),1:sz(1),1:sz(3));
figure; slice(x, y, z, old_img, 64, 64, 13.5);
shading flat; colormap(map); view(-66, 66);
figure; slice(x1, y1, z1, new_img, sz(1)/2, sz(2)/2, sz(3)/2);
shading flat; colormap(map); view(-66, 66);

Example 2 (2D interpolation):
load mri.mat; old_img=D(:,:,1,13)';
old_M = [1 0 0; 0 1 0; 0 0 1];
new_img = affine(old_img, old_M, [.2 .4]);
figure; image(old_img); colormap(map);
figure; image(new_img); colormap(map);

Appendix: Common 3D Affine matrices:

Translation (displacement of [dX dY dZ] for all voxels):
old_M = [
1 0 0 dX
0 1 0 dY
0 0 1 dZ
0 0 0 1 ];

Rotation (about X axis):
old_M = [
1 0 0 0
0 cosX -sinX 0
0 sinX cosX 0
0 0 0 1 ];

old_M = [
sX 0 0 0
0 sY 0 0
0 0 sZ 0
0 0 0 1 ];

License: Shareware

Related: Download, bresenham, Generation, Algorithm, Special, larger, Error, Implementation, inspired, Software

O/S:BSD, Linux, Solaris, Mac OS X

File Size: 10.0 KB

Downloads: 7

More Similar Code

slicing image with background using 2 threshold values

Random Image with Link is multi-platform compatible. This JavaScript allows you to generate a random image with link. It does require some customization so only experienced developers should use it. You will need to change link information, image...

Sometimes, rows or columns (or both) of a displayed matrix or vector have different meanings, and it would be nice to display them along with the matrix (instead of, say, remembering that the third row holds a given property of a set of data...

A: image matrix
sz: noise ratio (0 to 100) of the image

This function take an image and noise ratio then output a grayscaled image with uniform noise.

The uniform noise ranged from 0 to 255.

IMGAUSSIAN filters an 1D, 2D color/greyscale or 3D image with a Gaussian filter.

Instead of using a multidimensional Gaussian kernel, it uses the fact that a Gaussian kernel can be separated in 1D kernels.

By the default the...

Allows you to browse all images on your blog by date and/or category, with the ability to also search image captions for keywords.

Installation :

Activate the plugin. Add [imagebrowser] shortcode to a new or existing page.

This Function HistConnect will make a smooth histogram for a signal or image consisting of a few samples. The function assumes correlation between the samples, and implicitly generates new linear-interpolated samples between the originate samples....

IMSHADE will plot a matrix representing topography as a 3-component color image, with intensity proportional to the magnitude of the topographic slope of each pixel. Optionally, it can take an argument for lighting angle to use the directional...

Tristan Ursell
Sub-pixel Resolved 2D Convolution
March 2012


This function takes an input matrix mat1 and creates an image of the
matrix mat2 at the position (x,y) in mat1. If...

Display image with non-linearly spaced axis.
UIMAGE(X,Y,C) displays matrix C as an image, using the vectors X and Y to specify the X and Y coordinates. X and Y may be unevenly spaced vectors, but must be increasing. The size of C must be...

User Review for Resampling volume or image with affine matrix
- required fields

Please enter text on the image