

ksp1= importdata('MRI_kspace_data.txt');

ksp2= ksp1(:,1) + ksp1(:,2)*j;

ksp = reshape(ksp2,256,256);

figure(2)
image(1e6*abs(ksp))
colormap(gray)


figure(3)
imagesc(angle(ksp))
colormap(gray)

figure(4)
image(1e6*real(ksp))
colormap(gray)

figure(5)
image(1e6*imag(ksp))
colormap(gray)



im= fftshift( ifft2(ksp) );
figure(6)
imagesc(abs(im))
colormap(gray)

%------------------------------- Lecture 2 code

% reconstruction from k-space magnitude only
im1= fftshift( ifft2(abs(ksp)) );
figure(7)
imagesc(abs(im1))
colormap(gray)

% reconstruction from k-space phase only
im2= fftshift( ifft2( exp(j*angle(ksp))) );
figure(8)
imagesc(abs(im2))
colormap(gray)


% quantization 
im3= abs(im);
N= 10;

immax= max(max(im3));
im3q= round(im3/immax*(2^N-1));
figure(9)
imagesc(im3q)
colormap(gray)


%--- sampling change

size1= size(ksp);
N1= size1(1);
N2= size1(2);

% middle N2/2
ksps1= ksp(:,N2/4+1:N2*3/4);
ims1= fftshift( ifft2(ksps1) );
figure(10)
imagesc(abs(ims1))
colormap(gray)


% undersampling by a factor of 2
ksps2= ksp(:,1:2:N2);
ims2= fftshift( ifft2(ksps2) );
figure(11)
imagesc(abs(ims2))
colormap(gray)



% ---- dicom image read
dim = dicomread('CT_000043.dcm');
figure(12);
imagesc(dim)
colormap(gray)
%imtool(dim)

% -- ROI extraction

% MRI image: 256x256 - extract ROI from 200:230 (x), 110:130(y)
figure(13);
rangex= 200:230;
rangey= 110:130;
%roi= abs(im(200:230, 110:130));
roi= abs(im(rangex,rangey));
imroi= abs(im);
imroi(rangex,rangey)= max(max(abs(im)));

imagesc(imroi)
colormap(gray)




