Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
KanNudimmud authored Jul 7, 2023
1 parent cdf1c33 commit 020944f
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 0 deletions.
Binary file added advancedAMD.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added alzheimerBrain.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added earlyAMD.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
92 changes: 92 additions & 0 deletions image_registration.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
%% Image Registration
% Sources:
% National Eye Institute
% National Institute on Aging
%% Geometric Transformations
% Load the data
early = imread('earlyAMD.jpg');
advanced = imread('advancedAMD.jpg');

% Display them
figure(1)
imshowpair(advanced,early,'montage')
title('Original Images')

% Rotate advanced AMD (Age-related macular degeneration)
rotatedAdv = imrotate(advanced,90);

% Resize rotated advanced AMD to 10% larger
resizedAdv = imresize(rotatedAdv,1.1);

% Translate resized advanced AMD
shiftedAdv = imtranslate(resizedAdv,[5 10]);

% Display the last version with early AMD
figure(2)
imshowpair(shiftedAdv,early)
title('Geometrically Transformed Images')

%% Automating Registration
% Estimate the similarity transformation, advanced as moving, eary as fixed image
transAMD = imregcorr(advanced,early);

% Extract the transformation matrix
Tmat = transAMD.T;

% Apply the transformation
advTrans = imwarp(advanced,transAMD);

% Display auto-transformed advanced AMD
figure(3)
imshowpair(advTrans,early)
title('Auto-Transformed Advanced AMD')

%% Translation with Spatial Reference
% Extract size of images (moving and fixed)
movSize = size(advTrans);
fixSize = size(early);

% Create a spatial referencing object
spFixed = imref2d(fixSize);

% Transformation with spatial reference
advtransp = imwarp(advanced,transAMD,'OutputView',spFixed);

% Display spatially transformed advanced AMD
figure(4)
imshowpair(advtransp,early)
title('Spatially Transformed Advanced AMD')

%% What about more complex tranformations ?
%% Register Brain Scans with Control Points
% Load images
normal = imread('normalBrain.png');
alzheimer = imread('alzheimerBrain.png');

% Display them
figure(5)
imshowpair(alzheimer,normal,'montage')
title('Alzheimer vs Normal Brain Scans')

% Define control points
normalP = [173.375 377.375; 223.125 375.375; 81.875 126.125; 311.625 87.375];
alzheimerP = [155.375 357.375; 207.625 360.875; 71.375 134.625; 293.925 121.575];

% Adjust control points for the moving image
alzheimerP = cpcorr(alzheimerP,normalP,alzheimer,normal);

% Create a geometric transformation
Tform = fitgeotrans(alzheimerP,normalP,'affine');

% Create a spatial reference
spFixed = imref2d(size(normal));

% Apply transformation
alzheimerTrans = imwarp(alzheimer,Tform,'OutputView',spFixed);

% Visualize transformation
figure(6)
imshowpair(normal,alzheimerTrans)
title('Purple Areas are brighter in Alzheimer')

%% end
Binary file added normalBrain.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 020944f

Please sign in to comment.