-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
55ba186
commit 3d6baa1
Showing
19 changed files
with
1,702 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
function Cor=AffImFcn(x,Im1,Im2) | ||
|
||
tform = affine2d([x(1) 0 0; 0 x(2) 0; 0 0 1]); | ||
temp = imwarp(Im1,tform); | ||
temp2=imrotate(temp,x(3)); | ||
c = normxcorr2(Im2,temp2); | ||
|
||
Cor=1-max(c(:)); | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
% | ||
% Program to damp Gibb's Oscillation in FFTs | ||
% mixing one side into the other, with a gaussian weight | ||
% | ||
% by Reto Fiolka, 7.11.2008 | ||
% | ||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
|
||
|
||
function c=DampEdgeC(a,w)%Bild einlesen | ||
a=double(a); | ||
b=double(a); | ||
%w=40; %weite des zu mixenden Randes | ||
xdim=size(a,2); | ||
%Konstruktion der Gewichtungsfunktion | ||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
x=1:2*w; | ||
we=exp(-(x-w).^2/(round(w/2)^2))/2+0.5; | ||
weL=we(1:w); | ||
weR=we(w+1:end); | ||
weLI=1-weL; %inverse Gewichtung | ||
weRI=1-weR; | ||
|
||
|
||
%a=a(1:1024,1:1024); | ||
|
||
bordL=a(:,end-w:end); %dieser Rand wird auf der anderen Seite dann reingemixt | ||
bordR=a(:,1:w); | ||
bordR=a(:,1:w); | ||
bordL=a(:,end-w+1:end); | ||
bordU=a(1:w,:); | ||
bordO=a(end-w+1:end,:); | ||
bordU=flipud(bordU); %spiegeln | ||
bordO=flipud(bordO); | ||
bordL=fliplr(bordL); | ||
bordR=fliplr(bordR); | ||
|
||
%Gewichtung der R�nder | ||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
bordL=bordL.*repmat(weLI,[xdim,1]); | ||
a(:,end-w+1:end)=a(:,end-w+1:end).*repmat(weR,[xdim,1]); | ||
|
||
bordR=bordR.*repmat(weRI,[xdim,1]); | ||
a(:,1:w)=a(:,1:w).*repmat(weL,[xdim,1]); | ||
|
||
bordO=bordO.*repmat(weLI',[1,xdim]); | ||
a(end-w+1:end,:)=a(end-w+1:end,:).*repmat(weR',[1,xdim]); | ||
|
||
bordU=bordU.*repmat(weRI',[1,xdim]); | ||
a(1:w,:)=a(1:w,:).*repmat(weL',[1,xdim]); | ||
|
||
%reinmixen der R�nder | ||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
a(:,end-w+1:end)=(a(:,end-w+1:end)+bordR); | ||
a(:,1:w)=(a(:,1:w)+bordL); | ||
|
||
a(end-w+1:end,:)=(a(end-w+1:end,:)+bordU); | ||
a(1:w,:)=(a(1:w,:)+bordO); | ||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
|
||
%Im �berlapp nehme ich die Original Bildinformation | ||
a(1:w,1:w)=b(1:w,1:w); | ||
a(end-w:end,1:w)=b(end-w:end,1:w); | ||
a(1:w,end-w:end)=b(1:w,end-w:end); | ||
a(end-w:end,end-w:end)=b(end-w:end,end-w:end); | ||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
|
||
c=a; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
function [S1,S2,S3,M]=Demod(X0,X1,X2,phasex0,phasex1,phasex2) | ||
|
||
%This function solves the linear equation system for HELM | ||
% | ||
% Reto Fiolka, 17.07.2007 | ||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
X=[X0; X1; X2]; | ||
i=sqrt(-1); | ||
m=2; | ||
M=[m exp(i*phasex0) exp(-i*phasex0); | ||
m exp(i*phasex1) exp(-i*phasex1); | ||
m exp(i*phasex2) exp(-i*phasex2)]; Kondition=cond(M) | ||
Minv=inv(M); | ||
|
||
S=zeros(size(X)); | ||
[a1,b1]=size(X0); | ||
for i=1:a1 | ||
temp=Minv*([X(i,1:b1); X(i+a1,1:b1); X(i+2*a1,1:b1)]); | ||
S(i,:)=temp(1,:);S(a1+i,:)=temp(2,:); S(2*a1+i,:)=temp(3,:); | ||
end | ||
clear('X','X0','X1','X2') | ||
S1=S(1:a1,1:b1); %original spectra | ||
S2=S(1+a1:2*a1,1:b1); %shifted spectra (+u) | ||
S3=S(1+2*a1:3*a1,1:b1); %shifted spectra (-u) | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
function T=Triangle(r,xdim,ydim,midy,midx) | ||
T=zeros(xdim,ydim); | ||
for i = 1:xdim | ||
for j = 1:ydim | ||
|
||
x=i-xdim/2-midx; y=j-ydim/2-midy; | ||
R=sqrt((x^2+y^2)); | ||
%disk | ||
if((x^2+y^2)<r^2) | ||
T(i,j)=1-R/r; | ||
end | ||
|
||
end | ||
end | ||
|
||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
function T=Triangle3D(r,xdim,ydim,zdim,midy,midx,midz) | ||
T=zeros(xdim,ydim,zdim); | ||
for i = 1:xdim | ||
for j = 1:ydim | ||
for k = 1:zdim | ||
|
||
x=i-xdim/2-midx; | ||
y=j-ydim/2-midy; | ||
z=k-round(zdim/2)-midz; | ||
R=sqrt((x^2+y^2+z^2)); | ||
%disk | ||
if((x^2+y^2+(z*xdim/zdim*2.5)^2)<r^2) | ||
T(i,j,k)=1-R/r; | ||
|
||
end | ||
end | ||
end | ||
|
||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
function A=imresize3d(V,scale,tsize,ntype,npad) | ||
% This function resizes a 3D image volume to new dimensions | ||
% Vnew = imresize3d(V,scale,nsize,ntype,npad); | ||
% | ||
% inputs, | ||
% V: The input image volume | ||
% scale: scaling factor, when used set tsize to []; | ||
% nsize: new dimensions, when used set scale to []; | ||
% ntype: Type of interpolation ('nearest', 'linear', or 'cubic') | ||
% npad: Boundary condition ('replicate', 'symmetric', 'circular', 'fill', or 'bound') | ||
% | ||
% outputs, | ||
% Vnew: The resized image volume | ||
% | ||
% example, | ||
% load('mri','D'); D=squeeze(D); | ||
% Dnew = imresize3d(D,[],[80 80 40],'nearest','bound'); | ||
% | ||
% This function is written by D.Kroon University of Twente (July 2008) | ||
|
||
% Check the inputs | ||
if(exist('ntype', 'var') == 0), ntype='nearest'; end | ||
if(exist('npad', 'var') == 0), npad='bound'; end | ||
if(exist('scale', 'var')&&~isempty(scale)), tsize=round(size(V)*scale); end | ||
if(exist('tsize', 'var')&&~isempty(tsize)), scale=(tsize./size(V)); end | ||
|
||
% Make transformation structure | ||
T = makehgtform('scale',scale); | ||
tform = maketform('affine', T); | ||
|
||
% Specify resampler | ||
R = makeresampler(ntype, npad); | ||
|
||
% Resize the image volueme | ||
A = tformarray(V, tform, R, [1 2 3], [1 2 3], tsize, [], 0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
function cut=kreis(r,xdim,ydim,midy,midx) | ||
cut=zeros(xdim,ydim); | ||
for i = 1:xdim | ||
for j = 1:ydim | ||
|
||
x=i-xdim/2-midx; y=j-ydim/2-midy; | ||
|
||
%disk | ||
if((x^2+y^2)<r^2) | ||
cut(i,j)=cut(i,j)+1; | ||
end | ||
|
||
end | ||
end | ||
|
||
end | ||
|
||
|
69 changes: 69 additions & 0 deletions
69
2023-POPSIM/+SupFun/register2D_intensity_multiscale_affine.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
function [movingRegistered, transform] = register2D_intensity_multiscale_affine(im1,im2, initial_transform, initialise, downsample_factor, mode, iterations, type, min_I) | ||
|
||
% iterate through the downsampling: | ||
n_scales = length(downsample_factor); | ||
|
||
% set up the basic registration settings | ||
[optimizer, metric] = imregconfig(mode); | ||
|
||
% 1+1 evolutionary | ||
optimizer.InitialRadius = optimizer.InitialRadius/3.5; % this appears more stable, c.f. the documentation in matlab for aligning medical images. | ||
|
||
% prep the initial image. -> create the intermediate images for | ||
% registration. | ||
im1_ = im1; im2_ = im2; | ||
im1_(im1<10) = round(mean(im1_(:))); | ||
im2_(im2<10) = round(mean(im2_(:))); | ||
|
||
im1_ = im2double(im1_); %imgch0(imgch0 < 0.01) = mean(imgch0(:)); % the mean padding is somewhat essential???? | ||
im2_ = im2double(im2_); %imgch1(imgch1 < 0.01) = mean(imgch1(:)); | ||
|
||
im1_ = imadjustn(im1_); | ||
im2_ = imadjustn(im2_); | ||
|
||
for level=1:n_scales | ||
% downsample image to correct scale. # or is this the bad thing? | ||
img1_ = imresize(im1_, 1./downsample_factor(level), 'bilinear'); | ||
img2_ = imresize(im2_, 1./downsample_factor(level), 'bilinear'); | ||
|
||
% contrast adjust? | ||
img1_ = reshape(imadjust(img1_(:)), size(img1_)); | ||
img2_ = reshape(imadjust(img2_(:)), size(img2_)); % this does the same job as imadjustn | ||
optimizer.MaximumIterations = iterations(level); % set the specified number of iterations at this level. | ||
|
||
if level == 1 | ||
if initialise==1 | ||
% scale the initial transform (defined for the full volume to a subvolume for the translation). | ||
initial_transform(3,1:2) = initial_transform(3,1:2) / double(downsample_factor); % we assume the initial transform is for the full scale. | ||
initial_transform = affine3d(initial_transform); % for some reason this initialisation is not good? | ||
initial_transform.T % print for debugging. | ||
tform = imregtform(img2_, img1_, type, optimizer, metric, 'InitialTransformation', initial_transform, 'PyramidLevels', 1); | ||
else | ||
% 'new registration' | ||
tform = imregtform(img2_, img1_, type, optimizer, metric, 'PyramidLevels', 1); | ||
% tform.T | ||
% '====' | ||
end | ||
else | ||
% we use the previous to initialise. | ||
tf_prev = tform.T; | ||
tf_prev(3,1:2) = tf_prev(3,1:2) * double(downsample_factor(level-1)/downsample_factor(level)); % correct for translational discrepancy. | ||
tform = affine2d(tf_prev); | ||
tform = imregtform(img2_, img1_, type, optimizer, metric, 'InitialTransformation', tform, 'PyramidLevels', 1); | ||
% tform.T | ||
% '====' | ||
end | ||
end | ||
|
||
% (z,y,x) in python convention. | ||
transform = tform.T; % grab the matrix | ||
transform = transform'; % transpose the matrix | ||
transform(1:2,3) = transform(1:2,3)*downsample_factor(length(downsample_factor)); %multiply the last column by the very last downsample_factor. | ||
|
||
% if return_img == 1 | ||
tform.T = transform'; % update the matrix inside. | ||
movingRegistered = imwarp(im2, tform,'OutputView', imref2d(size(im1))); | ||
% % save the image as tiff. | ||
% saveastiff(movingRegistered, outsavefile) | ||
|
||
end |
69 changes: 69 additions & 0 deletions
69
2023-POPSIM/+SupFun/register3D_intensity_multiscale_affine.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
function [movingRegistered, transform] = register3D_intensity_multiscale_affine(im1,im2, initial_transform, initialise, downsample_factor, mode, iterations, type, min_I) | ||
|
||
% iterate through the downsampling: | ||
n_scales = length(downsample_factor); | ||
|
||
% set up the basic registration settings | ||
[optimizer, metric] = imregconfig(mode); | ||
|
||
% 1+1 evolutionary | ||
optimizer.InitialRadius = optimizer.InitialRadius/3.5; % this appears more stable, c.f. the documentation in matlab for aligning medical images. | ||
|
||
% prep the initial image. -> create the intermediate images for | ||
% registration. | ||
im1_ = im1; im2_ = im2; | ||
im1_(im1<10) = round(mean(im1_(:))); | ||
im2_(im2<10) = round(mean(im2_(:))); | ||
|
||
im1_ = im2double(im1_); %imgch0(imgch0 < 0.01) = mean(imgch0(:)); % the mean padding is somewhat essential???? | ||
im2_ = im2double(im2_); %imgch1(imgch1 < 0.01) = mean(imgch1(:)); | ||
|
||
im1_ = imadjustn(im1_); | ||
im2_ = imadjustn(im2_); | ||
|
||
for level=1:n_scales | ||
% downsample image to correct scale. # or is this the bad thing? | ||
img1_ = SupFun.imresize3d(im1_, 1./downsample_factor(level)); | ||
img2_ = SupFun.imresize3d(im2_, 1./downsample_factor(level)); | ||
|
||
% contrast adjust? | ||
img1_ = reshape(imadjust(img1_(:)), size(img1_)); | ||
img2_ = reshape(imadjust(img2_(:)), size(img2_)); % this does the same job as imadjustn | ||
optimizer.MaximumIterations = iterations(level); % set the specified number of iterations at this level. | ||
|
||
if level == 1 | ||
if initialise==1 | ||
% scale the initial transform (defined for the full volume to a subvolume for the translation). | ||
initial_transform(4,1:3) = initial_transform(4,1:3) / double(downsample_factor); % we assume the initial transform is for the full scale. | ||
initial_transform = affine3d(initial_transform); % for some reason this initialisation is not good? | ||
initial_transform.T % print for debugging. | ||
tform = imregtform(img2_, img1_, type, optimizer, metric, 'InitialTransformation', initial_transform, 'PyramidLevels', 1); | ||
else | ||
% 'new registration' | ||
tform = imregtform(img2_, img1_, type, optimizer, metric, 'PyramidLevels', 1); | ||
% tform.T | ||
% '====' | ||
end | ||
else | ||
% we use the previous to initialise. | ||
tf_prev = tform.T; | ||
tf_prev(4,1:3) = tf_prev(4,1:3) * double(downsample_factor(level-1)/downsample_factor(level)); % correct for translational discrepancy. | ||
tform = affine3d(tf_prev); | ||
tform = imregtform(img2_, img1_, type, optimizer, metric, 'InitialTransformation', tform, 'PyramidLevels', 1); | ||
% tform.T | ||
% '====' | ||
end | ||
end | ||
|
||
% (z,y,x) in python convention. | ||
transform = tform.T; % grab the matrix | ||
transform = transform'; % transpose the matrix | ||
transform(1:3,4) = transform(1:3,4)*downsample_factor(length(downsample_factor)); %multiply the last column by the very last downsample_factor. | ||
|
||
% if return_img == 1 | ||
tform.T = transform'; % update the matrix inside. | ||
movingRegistered = imwarp(im2, tform,'OutputView', imref3d(size(im1))); | ||
% % save the image as tiff. | ||
% saveastiff(movingRegistered, outsavefile) | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
function [ output ] = shear3DinDim2(inArray, angle, bReverse, dz, xypixelsize, trans, fillVal) | ||
%shear3DinDim2 -- deskew inArray about the 1st dimension (y in image terms) | ||
%x in sheet-scan terms) | ||
% inArray -- input 3D array | ||
% angle -- skewing angle | ||
% bReverse -- is skewing in reverse direction ? (like in Bi-Chang's data) | ||
% dz -- sample-scan step size (in microns) | ||
% xypixelsize -- in microns | ||
% trans -- extra left-right translation (positive number translates the result toward | ||
% the right) | ||
% fillVal -- use this value to fill the new void | ||
|
||
center = (size(inArray)+1)/2; | ||
trans1 = [1 0 0 0 | ||
0 1 0 0 | ||
0 0 1 0 | ||
-center 1]; | ||
|
||
rot = [1 0 0 0 | ||
0 1 0 0 | ||
0 cos(angle*pi/180)*dz/xypixelsize 1 0 | ||
0 0 0 1]; | ||
|
||
if bReverse | ||
rot(3, 2) = -rot(3, 2); | ||
end | ||
|
||
% widenBy = ceil(size(inArray, 2) * xypixelsize /(cos(angle*pi/180)*dz)); | ||
widenBy = ceil(size(inArray, 3)*cos(angle*pi/180)*dz/xypixelsize); | ||
|
||
|
||
trans2 = [1 0 0 0 | ||
0 1 0 0 | ||
0 0 1 0 | ||
center+[0 widenBy/2+trans 0] 1]; | ||
|
||
T = trans1*rot*trans2; | ||
tform = maketform('affine', T); | ||
R = makeresampler('cubic', 'fill'); | ||
output = tformarray(inArray, tform, R, [1 2 3], [1 2 3], size(inArray)+[0 widenBy 0] , [], fillVal); | ||
|
||
end |
Oops, something went wrong.