Skip to content

Instantly share code, notes, and snippets.

@danielronnkvist
Created December 6, 2014 09:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielronnkvist/45c36e0ca13fd672bc2c to your computer and use it in GitHub Desktop.
Save danielronnkvist/45c36e0ca13fd672bc2c to your computer and use it in GitHub Desktop.
Lab 2 TNM087
%% A
cWhite = imread('CWhite1.jpg');
hWhite = imread('HWhite1.jpg');
N = 512
cWhite512 = imresize(cWhite, [512 512]);
hWhite512 = imresize(hWhite, [512 512]);
[X,Y] = meshgrid((1:N));
[T,R] = cart2pol(X-N/2, Y-N/2);
plot(R(N/2, :));
figure
imshow(R, [])
%% B
SR = R/255;
M = 100;
QR = round((SR/max(max(SR)))*M);
max(max(QR))
min(min(QR))
for m=0:M
Maskm(:,:,(m+1)) = (QR(:,:) == m);
end
Maskm = im2uint8(Maskm);
%%
rc = [];
rh = [];
for m=1:M+1
rc(m) = mean(mean(Maskm(:,:,m) .* cWhite512(:,:)));
rh(m) = mean(mean(Maskm(:,:,m) .* hWhite512(:,:)));
end
rc_norm=rc./max(rc);
rh_norm=rh./max(rh);
plot(rc)
figure
plot(rh)
figure
plot(rc_norm)
figure
plot(rh_norm)
close all
img=imread('BoldRedEye.jpg');
redChannel = double(img(:,:,1));
% imshow(redChannel);
load('RedEyeMask.mat')
filter = ones(64, 64);
MFilterImage=imfilter(redChannel,filter);
% imshow(MFilterImage)
% figure
EyeFilterImage=imfilter(redChannel,RedEyeMask);
% imshow(EyeFilterImage)
ratio=EyeFilterImage./MFilterImage;
figure
imshow(ratio)
% ratio(ratio < 0.34)=0;
ratio(ratio < quantile(quantile(ratio,0.99),0.99))=0;
M=imfilter(imregionalmax(ratio),RedEyeMask);
imshow(M);
figure
imshowpair(M,img)
clear all
close all
Gim=imread('GCPins512.jpg');
Him=imread('GHPins512.jpg');
imshow(Gim)
[GX,GY] = ginput(4);
hold on
imshow(Him)
[HX,HY] = ginput(4);
GC = [GX, GY];
HC = [HX, HY];
GC1 = [GC, ones(4,1)];
HC1 = [HC, ones(4,1)];
A = mldivide(HC1, GC1);
%%
A(1,3)=0; A(2,3)=0; A(3,3)=1;
fix = imref2d(size(Gim))
newimg = imwarp(Him, affine2d(A), 'nearest', 'OutputView', fix);
imshowpair(newimg, Gim);
%%
close all
newim = ones(500,512);
for x=1:500
for y=1:512
pos = A^(-1)*[x;y;1];
pos = pos/pos(3);
if pos(1) > 1 && pos(2) > 1 && pos(1) < 500 && pos(2) < 512
newim(x,y) = Gim(round(pos(1)), round(pos(2)));
end
end
end
imshow(newim, [])
figure
imshow(Gim, [])
figure
imshow(Him, [])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment