Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %
- %%Assignment1 by Baylie Meredith
- %%
- function assign(folder)
- clc();
- if ~exist('folder','var')
- folder = '.\data\HomeC002\';
- end
- disp(folder);
- % load Depth and RGB images.
- tempload = load([folder,'\PSLR_C01_120x160.mat']);
- RGB = tempload.CC;
- tempload = load([folder,'\PSLR_D01_120x160.mat']);
- DEPTH= tempload.CR;
- L = DEPTH.N;
- global globvar1;
- globvar1=[];
- globvar1.flagPause=0;
- %% Create figure, where we will show Depth & RGB
- figure(1);
- clf();
- % Subfigure, for Depth
- subplot(2,1,1) ;
- depthinr = DEPTH.R(:,:,1);
- HandleDepth = imagesc(depthinr);
- title('Depth');
- colormap gray;
- set(gca(),'xdir','reverse'); %flipping axes
- % In another subfigure, we show the associated RGB image.
- subplot(2,1,2);
- HandleColour = image(RGB.C(:,:,:,1));
- title('RGB');
- set(gca(),'xdir','reverse'); %flipping axes
- %% 3D points figure.
- figure(2);
- clf();
- HandleAxes = axes('position',[0.20,0.1,0.75,0.85]); %moves the 3D in the graph
- HandlePlot = plot3(HandleAxes,0,0,0,'.','markersize',2) ;
- axis([0,3,-1.5,1.5,-0.4,0.9]);
- title('3D');
- xlabel('X (m)');
- ylabel('Y (m)');
- zlabel('Z (m)');
- grid on;
- rotate3d on ;
- %% Some control buttons (you may define extra buttons, for other purposes)
- uicontrol('Style','pushbutton','String','Pause/Cont.','Position',[10,1,80,20],'Callback',{@MyCallBackA,1});
- uicontrol('Style','pushbutton','String','ETC','Position',[90,1,80,20],'Callback',{@MyCallBackA,2});
- uicontrol('Style','slider','Position',[10,50,40,150],'Callback',{@MyCallBackB,1});
- uicontrol('Style','checkbox','Position',[20,250,30,50],'Callback',{@MyCallBackForCheckBox1});
- oradius = input('Outer radius =')
- iradius = input('Inner radius =')
- i=0;
- while 1 %neverending loop like 2121
- while (globvar1.flagPause) %while this flagpause is true
- pause(0.3); %stops and checks every 0.3 seconds whether flagpause has been turned off
- end
- i=i+1;
- if i > L
- break;
- end
- depthinr = DEPTH.R(:,:,i);
- set(HandleColour,'cdata',RGB.C(:,:,:,i)); % show RGB image
- set(HandleDepth,'cdata',depthinr);
- % obtain 3D points, for those pixels which are not faulty.
- Goodpixel = find(depthinr>0);
- [row,col] = find(depthinr>0);
- %changes the numbers on the 3D plot
- [xx,yy,zz] = ConvertSelectedDepthsTo3DPoints(single(depthinr)*0.001,Goodpixel,row,col);
- [xx,zz] = Rotate2D(xx,zz,10);
- zz = zz + 0.2;
- % Show the 3D points but not below -5 or above 100cm
- cutindexes1 = find (zz < -0.05);
- cutindexes2 = find (zz > 1);
- [xx,yy,zz] = CutOff(xx,yy,zz,cutindexes1);
- [xx,yy,zz] = CutOff(xx,yy,zz,cutindexes2);
- redouter = find(xx.^2 +yy.^2 = )
- set(HandlePlot,'xdata',xx,'ydata',yy,'zdata',newz2);
- pause(0.1);
- end
- end
- % ---------------------------------------
- % Callback function. I defined it, and associated it to certain GUI button,
- function MyCallBackA(~,~,x)
- global globvar1;
- if (x == 1)
- globvar1.flagPause = ~globvar1.flagPause; %Switch ON->OFF->ON -> and so on.
- disp(x);disp(globvar1.flagPause);
- return;
- end
- if (x==2)
- disp('you pressed ETC!');
- return;
- end
- return;
- end
- % ...............................................
- % I associated the following function, as a callback function for one slider control.
- % Each time a new value is set, in the slider, our function is called
- function MyCallBackB(a,~,~)
- % When the system calls our callback function,
- % it offers us the handle of the slider object itself, through the argument
- % "a"
- v = get(a,'value'); % the property "value" is the current
- % value of the slider (position of the selector)
- % You may use it to set the value of certain relevant variable,
- % in your program.
- % Here, I just print its value, for testing purposes.
- disp(v) ;
- % BTW: the object ("a"), has many other properties; you may inspect them.
- return;
- end
- % ---------------------------------------
- % I associated this function, as a callback function for one CheckBox.
- % Each time the state of the checkbx is modified, our function is called
- function MyCallBackForCheckBox1(a,~,~)
- % when the system calls our callback function,
- % it offers us the handle of the object, through the argument
- % "a"
- v = get(a,'value'); % the property "value" is the current
- % value of the checkbox object.
- disp(v) ;
- % You may use it to set the value of certain relevant variable,
- % in your program.
- % Here, I just print its value, for testing purposes.
- % BTW: the object ("a"), has many other properties; you may inspect them.
- return;
- end
- % ---------------------------------------
- function [xx,yy,zz] = ConvertSelectedDepthsTo3DPoints(depthfunc, Goodpixels, r,c)
- xx = depthfunc(Goodpixels);
- yy = depthfunc(Goodpixels).*(c-80)*4/594;
- zz = -depthfunc(Goodpixels).*(r-60)*4/592;
- end
- % ---------------------------------------
- function [xx,zz] = Rotate2D(xcoord,zcoord,angle)
- angle = angle*pi/180;
- xx = xcoord*cos(angle)+ zcoord*sin(angle);
- zz = xcoord*-sin(angle)+ zcoord*cos(angle);
- end
- %---------------------------------------
- function [xx,yy,zz] = CutOff(xx,yy,zz,cutindices)
- zz = zz(cutindices)
- yy = yy(cutindices)
- xx = xx(cutindices)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement