Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.30 KB | None | 0 0
  1. %
  2. %%Assignment1 by Baylie Meredith
  3. %%
  4. function assign(folder)
  5. clc();
  6. if ~exist('folder','var')
  7. folder = '.\data\HomeC002\';
  8. end
  9.  
  10. disp(folder);
  11.  
  12. % load Depth and RGB images.
  13. tempload = load([folder,'\PSLR_C01_120x160.mat']);
  14. RGB = tempload.CC;
  15. tempload = load([folder,'\PSLR_D01_120x160.mat']);
  16. DEPTH= tempload.CR;
  17.  
  18. L = DEPTH.N;
  19. global globvar1;
  20. globvar1=[];
  21. globvar1.flagPause=0;
  22.  
  23. %% Create figure, where we will show Depth & RGB
  24. figure(1);
  25. clf();
  26.  
  27. % Subfigure, for Depth
  28. subplot(2,1,1) ;
  29. depthinr = DEPTH.R(:,:,1);
  30. HandleDepth = imagesc(depthinr);
  31. title('Depth');
  32. colormap gray;
  33. set(gca(),'xdir','reverse'); %flipping axes
  34.  
  35. % In another subfigure, we show the associated RGB image.
  36. subplot(2,1,2);
  37. HandleColour = image(RGB.C(:,:,:,1));
  38. title('RGB');
  39. set(gca(),'xdir','reverse'); %flipping axes
  40.  
  41. %% 3D points figure.
  42. figure(2);
  43. clf();
  44.  
  45. HandleAxes = axes('position',[0.20,0.1,0.75,0.85]); %moves the 3D in the graph
  46. HandlePlot = plot3(HandleAxes,0,0,0,'.','markersize',2) ;
  47. axis([0,3,-1.5,1.5,-0.4,0.9]);
  48. title('3D');
  49. xlabel('X (m)');
  50. ylabel('Y (m)');
  51. zlabel('Z (m)');
  52. grid on;
  53. rotate3d on ;
  54.  
  55. %% Some control buttons (you may define extra buttons, for other purposes)
  56.  
  57. uicontrol('Style','pushbutton','String','Pause/Cont.','Position',[10,1,80,20],'Callback',{@MyCallBackA,1});
  58. uicontrol('Style','pushbutton','String','ETC','Position',[90,1,80,20],'Callback',{@MyCallBackA,2});
  59. uicontrol('Style','slider','Position',[10,50,40,150],'Callback',{@MyCallBackB,1});
  60. uicontrol('Style','checkbox','Position',[20,250,30,50],'Callback',{@MyCallBackForCheckBox1});
  61.  
  62. oradius = input('Outer radius =')
  63. iradius = input('Inner radius =')
  64. i=0;
  65. while 1 %neverending loop like 2121
  66. while (globvar1.flagPause) %while this flagpause is true
  67. pause(0.3); %stops and checks every 0.3 seconds whether flagpause has been turned off
  68. end
  69.  
  70. i=i+1;
  71. if i > L
  72. break;
  73. end
  74.  
  75. depthinr = DEPTH.R(:,:,i);
  76. set(HandleColour,'cdata',RGB.C(:,:,:,i)); % show RGB image
  77. set(HandleDepth,'cdata',depthinr);
  78.  
  79. % obtain 3D points, for those pixels which are not faulty.
  80. Goodpixel = find(depthinr>0);
  81. [row,col] = find(depthinr>0);
  82. %changes the numbers on the 3D plot
  83. [xx,yy,zz] = ConvertSelectedDepthsTo3DPoints(single(depthinr)*0.001,Goodpixel,row,col);
  84. [xx,zz] = Rotate2D(xx,zz,10);
  85. zz = zz + 0.2;
  86.  
  87. % Show the 3D points but not below -5 or above 100cm
  88. cutindexes1 = find (zz < -0.05);
  89. cutindexes2 = find (zz > 1);
  90. [xx,yy,zz] = CutOff(xx,yy,zz,cutindexes1);
  91. [xx,yy,zz] = CutOff(xx,yy,zz,cutindexes2);
  92.  
  93. redouter = find(xx.^2 +yy.^2 = )
  94.  
  95.  
  96. set(HandlePlot,'xdata',xx,'ydata',yy,'zdata',newz2);
  97. pause(0.1);
  98. end
  99. end
  100. % ---------------------------------------
  101. % Callback function. I defined it, and associated it to certain GUI button,
  102. function MyCallBackA(~,~,x)
  103. global globvar1;
  104.  
  105. if (x == 1)
  106. globvar1.flagPause = ~globvar1.flagPause; %Switch ON->OFF->ON -> and so on.
  107. disp(x);disp(globvar1.flagPause);
  108. return;
  109. end
  110. if (x==2)
  111. disp('you pressed ETC!');
  112. return;
  113. end
  114. return;
  115. end
  116.  
  117. % ...............................................
  118. % I associated the following function, as a callback function for one slider control.
  119. % Each time a new value is set, in the slider, our function is called
  120. function MyCallBackB(a,~,~)
  121.  
  122. % When the system calls our callback function,
  123. % it offers us the handle of the slider object itself, through the argument
  124. % "a"
  125. v = get(a,'value'); % the property "value" is the current
  126. % value of the slider (position of the selector)
  127. % You may use it to set the value of certain relevant variable,
  128. % in your program.
  129. % Here, I just print its value, for testing purposes.
  130. disp(v) ;
  131.  
  132. % BTW: the object ("a"), has many other properties; you may inspect them.
  133. return;
  134. end
  135. % ---------------------------------------
  136. % I associated this function, as a callback function for one CheckBox.
  137. % Each time the state of the checkbx is modified, our function is called
  138. function MyCallBackForCheckBox1(a,~,~)
  139.  
  140. % when the system calls our callback function,
  141. % it offers us the handle of the object, through the argument
  142. % "a"
  143. v = get(a,'value'); % the property "value" is the current
  144. % value of the checkbox object.
  145. disp(v) ;
  146. % You may use it to set the value of certain relevant variable,
  147. % in your program.
  148. % Here, I just print its value, for testing purposes.
  149.  
  150. % BTW: the object ("a"), has many other properties; you may inspect them.
  151. return;
  152. end
  153. % ---------------------------------------
  154. function [xx,yy,zz] = ConvertSelectedDepthsTo3DPoints(depthfunc, Goodpixels, r,c)
  155. xx = depthfunc(Goodpixels);
  156. yy = depthfunc(Goodpixels).*(c-80)*4/594;
  157. zz = -depthfunc(Goodpixels).*(r-60)*4/592;
  158. end
  159. % ---------------------------------------
  160. function [xx,zz] = Rotate2D(xcoord,zcoord,angle)
  161. angle = angle*pi/180;
  162. xx = xcoord*cos(angle)+ zcoord*sin(angle);
  163. zz = xcoord*-sin(angle)+ zcoord*cos(angle);
  164. end
  165. %---------------------------------------
  166. function [xx,yy,zz] = CutOff(xx,yy,zz,cutindices)
  167. zz = zz(cutindices)
  168. yy = yy(cutindices)
  169. xx = xx(cutindices)
  170. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement