|
a |
|
b/task_final_praga.asv |
|
|
1 |
close all ; |
|
|
2 |
clear all ; |
|
|
3 |
clc; |
|
|
4 |
%%author - Praga |
|
|
5 |
%%process time - 13 sec (without thresholding) |
|
|
6 |
%% - 1 minute (with thresolding) |
|
|
7 |
%%%%%%%% Task 1 %%%%%%%%%%%%%%%%%%%%%%% |
|
|
8 |
%%the conditions for R %%%%%%%%%%%%%%%%%% |
|
|
9 |
|
|
|
10 |
%% 1) tan(theta/2) > R/Yp |
|
|
11 |
%% 2) Yus*cos(theta/2) > 2R |
|
|
12 |
%% 3) Xus*cos(theta/2) > 2R |
|
|
13 |
%% 4) Yus - Yp > R |
|
|
14 |
%% 5) Xus > 2R |
|
|
15 |
%% |
|
|
16 |
|
|
|
17 |
%%%%%%% Task 2 %%%%%%%%%%%%%%%%%%%%%%%%%% |
|
|
18 |
%%%%%%%%defining all the variables%%%%%%%% |
|
|
19 |
|
|
|
20 |
FOV=120; %degree |
|
|
21 |
theta=(pi*2)/180; %radian |
|
|
22 |
R=2; %cm |
|
|
23 |
Yp=6; %cm |
|
|
24 |
Xus=10; %cm |
|
|
25 |
Yus=10; %cm |
|
|
26 |
Sx=0.1; %cm |
|
|
27 |
Sy=0.1; %cm |
|
|
28 |
num_pixel=Xus/Sx; %done only for X as both are equal |
|
|
29 |
|
|
|
30 |
%%to get the main image over here |
|
|
31 |
[im_main]=createmainimage(Xus,R,theta,num_pixel); |
|
|
32 |
|
|
|
33 |
%%%%%%%%% Task 3 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
|
34 |
%%creation and visualization of the empty voxel%%% |
|
|
35 |
VoxelMat=zeros(num_pixel,num_pixel,num_pixel); |
|
|
36 |
|
|
|
37 |
for i=1:num_pixel |
|
|
38 |
for j=1:num_pixel |
|
|
39 |
for k=1:num_pixel |
|
|
40 |
if (i-num_pixel/2)^2+(j-num_pixel/2)^2+(k-num_pixel/2)^2<(R/Sx)^2 |
|
|
41 |
VoxelMat(i,j,k)=255; |
|
|
42 |
end |
|
|
43 |
|
|
|
44 |
end |
|
|
45 |
end |
|
|
46 |
end |
|
|
47 |
|
|
|
48 |
%view of voxels |
|
|
49 |
[vol_handle,FV]=VoxelPlotter(VoxelMat,1); |
|
|
50 |
view(3); |
|
|
51 |
daspect([1,1,1]); |
|
|
52 |
set(gca,'xlim',[0 num_pixel], 'ylim',[0 num_pixel], 'zlim',[0 num_pixel]); |
|
|
53 |
title('actual sphere in Voxels without the reconstruction algorithem'); |
|
|
54 |
|
|
|
55 |
|
|
|
56 |
%push of taken image back into a 3D array as reconstruction |
|
|
57 |
%reconstruction view will be differnt as it makes coding easy |
|
|
58 |
%rotating the reconstructed matrix by 90 degrees will give the original |
|
|
59 |
%will be working with X and Z axis |
|
|
60 |
|
|
|
61 |
%%nearest neighbour voxel mapping |
|
|
62 |
|
|
|
63 |
array_recon=zeros(num_pixel,num_pixel,num_pixel); |
|
|
64 |
angle_1=-pi/3:theta:pi/3; %in radians |
|
|
65 |
|
|
|
66 |
%special case handled first ....... |
|
|
67 |
%array_recon(:,:,num_pixel/2)=im_main(:,:,31); |
|
|
68 |
|
|
|
69 |
%delete the angle zero from array |
|
|
70 |
%angle_1= angle_1([1:30, 32:end]); |
|
|
71 |
|
|
|
72 |
for k=1:size(angle_1,2) |
|
|
73 |
%rotation matrix with respect to y axis |
|
|
74 |
%Rot = [cos(angle(k)) 0 sin(angle(k));0 1 0;-sin(angle(k)) 0 cos(angle(k))]; |
|
|
75 |
x=size(im_main,1); |
|
|
76 |
y=size(im_main,2); |
|
|
77 |
|
|
|
78 |
for i =1:1:x |
|
|
79 |
for j=1:1:y |
|
|
80 |
new_cord=rotx(angle_1(k)*180/pi)*[i,j,0]'; |
|
|
81 |
new_cord(3)=new_cord(3)+50; |
|
|
82 |
new_cord=ceil(new_cord); |
|
|
83 |
if new_cord(3)>0 |
|
|
84 |
array_recon(new_cord(1),new_cord(2),new_cord(3))=im_main(i,j,k); |
|
|
85 |
array_recon=uint8(array_recon); |
|
|
86 |
end |
|
|
87 |
|
|
|
88 |
end |
|
|
89 |
end |
|
|
90 |
end |
|
|
91 |
|
|
|
92 |
%%print voxel after nearest neighbour map |
|
|
93 |
figure; |
|
|
94 |
[array_recon_1]=VoxelPlotter(array_recon,1); |
|
|
95 |
view(3); |
|
|
96 |
daspect([1,1,1]); |
|
|
97 |
set(gca,'xlim',[0 num_pixel], 'ylim',[0 num_pixel], 'zlim',[0 num_pixel]); |
|
|
98 |
title('Voxels without the interpolation'); |
|
|
99 |
|
|
|
100 |
%%%%%bilinear interpolation %%%%%%%%%%%% |
|
|
101 |
zoomed=zeros(size(array_recon)); |
|
|
102 |
%%%bilinear interpolation |
|
|
103 |
for j=1:size(array_recon,3) |
|
|
104 |
zoomed(:,:,j)=bilinear( array_recon(:,:,j) ); |
|
|
105 |
end |
|
|
106 |
|
|
|
107 |
figure; |
|
|
108 |
[zoomed_1]=VoxelPlotter(zoomed,1); |
|
|
109 |
view(3); |
|
|
110 |
daspect([1,1,1]); |
|
|
111 |
set(gca,'xlim',[0 num_pixel], 'ylim',[0 num_pixel], 'zlim',[0 num_pixel]); |
|
|
112 |
title('Voxels after bilinear interpolation'); |
|
|
113 |
|
|
|
114 |
mkdir('imagesafterrecon'); |
|
|
115 |
cd('imagesafterrecon'); |
|
|
116 |
%save the image |
|
|
117 |
filename = 'p%d.bmp'; |
|
|
118 |
filename = sprintf(filename,image_index); |
|
|
119 |
image_index = image_index + 1; |
|
|
120 |
imwrite(im,filename); |