clear all close all clc format long %% The following two are correspondences % %% Data loading % load('.\Data\GoPro\GoPro_Right_Red\GX010103\CellLine\origin\cellLine_2048_2057_step_5_dimY_5_boiNum_1_FUSION.mat'); % startFrame = 2048; % endFrame = 2057; load('.\Data\GoPro\GoPro_Right_Red\GX010103\CellLine\origin\cellLine_1999_2001_step_5_dimY_5_boiNum_1_FUSION_5.mat'); startFrame = 1999; endFrame = 2001; parapath = 'E:\LSS\GoPro\CalibrationSession\Stereo\LW_458_RR_101\Standard\'; load(strcat(parapath,'stereoParams.mat')); %% cameraParams = stereoParams.CameraParameters2; % transformCalibration =[0 80 800]; transformCalibration = [0 20 800]; %% totalFrame = endFrame - startFrame + 1; %% Frame_base = 4; %% Range of FOI % foi_minX = 800; % foi_minY = 1200; %1200 % % foi_maxX = 1200; % foi_maxY = 1975; %2000 % foi_minY = 730; % foi_maxY = 1280; % For FUSION % foi_minY = 808; % foi_maxY = 1105; % foi_minX = 800; % foi_maxX = 2028; foi_minX = 1200; foi_maxX = 1605; % foi_minY = 850; % foi_maxY = 1350; % % foi_minX = 400; % foi_maxX = 1950; tic %% for i = startFrame:1:endFrame tempCell = cellLine{i, 1}; for j = 1:1:size(tempCell, 2) if size(tempCell(1,j).line,1) ~= 0 for numSeg = 1:1:size(tempCell(1, j).line(1).x,2) x1 = tempCell(1, j).line(1).x(1,numSeg).x; x2 = tempCell(1, j).line(2).x(1,numSeg).x; rate1 = tempCell(1, j).line(1).rate; rate1 = mean(extractfield(rate1, 'rate')); rate2 = tempCell(1, j).line(2).rate; rate2 = mean(extractfield(rate2, 'rate')); minX1 = min(x1); maxX1 = max(x1); minX2 = min(x2); maxX2 = max(x2); minX = max(minX1, minX2); maxX = min(maxX1, maxX2); %% FOI new added minX = max(minX, foi_minX); maxX = min(maxX, foi_maxX); if minX >= maxX continue; end stepX = minX:1:maxX; y1 = tempCell(1, j).line(1).para(1,numSeg).para(1)*stepX + tempCell(1, j).line(1).para(1,numSeg).para(2); y2 = tempCell(1, j).line(2).para(1,numSeg).para(1)*stepX + tempCell(1, j).line(2).para(1,numSeg).para(2); % min_y1 = min(y1); max_y1 = max(y1); % min_y2 = min(y2); max_y2 = max(y2); % if min_y1 < foi_minY || min_y2 < foi_minY || max_y1 > foi_maxY || max_y2 > foi_maxY % Pys = [ ]; % continue; % end diff = abs(y1-y2) ; if isnan(diff) continue; end %% Stack the image points imgPoints_1 = [y1' stepX']; imgPoints_2 = [y2' stepX']; worldPoints_1 = pointsToWorld(cameraParams, cameraParams.RotationMatrices(:,:,Frame_base), ... cameraParams.TranslationVectors(Frame_base,:) - transformCalibration, imgPoints_1); worldPoints_2 = pointsToWorld(cameraParams, cameraParams.RotationMatrices(:,:,Frame_base), ... cameraParams.TranslationVectors(Frame_base,:) - transformCalibration, imgPoints_2); for k = 1:1:length(stepX) pys_y(k) = norm(worldPoints_2(k,:) - worldPoints_1(k,:)); end Pys(1,j).diff(1,numSeg).diff = diff; Pys(1,j).pys_y(1,numSeg).pys_y = pys_y; Pys(1,j).rate(1,numSeg).rate = (rate1+rate2)/2; diff = []; pys_y = []; end end end PysCell{i,1} = Pys; toc end % %% Visualisation Diameter % % color = PlotColor(); % color matrix % for i = startFrame:1:endFrame % figure(i) % buffDist = []; % buffTempX = []; % tempCell = PysCell{i,1}; % for j = 1:1:size(tempCell, 2) % % % tempDist = tempCell(1,j).pys_y * 100; % tempDist = tempCell(1,j).pys_y ; % buffDist = [buffDist tempDist]; % tempX = 1:1:length(tempDist); % buffTempX = [buffTempX tempX]; % end % %% DBscan Parameters % epsilon = 10; % max distance between two points to be considered in one cluster 5 % MinPts = 500; % Minimum number of points in one cluster 8 % % m_c_id = DBSCAN(buffDist',epsilon,MinPts); % N_g = max(m_c_id); % % flag = []; % for h = 1:1:N_g % flag(h) = length(find(m_c_id == h)); % end % % maxindex = find(flag == max(flag)); % buffDist = buffDist(1,find(m_c_id == maxindex)); % % buffTempX = linspace(1,length(buffDist),length(buffDist)); % %% % plot(1:1:length(buffTempX), buffDist, 'r.'); % xlabel('Pixel','FontSize',16); % ylabel('Diameter(mm)','FontSize',16); % set(gca,'FontSize',15); % axis tight % hold on % % MEAN(i) = mean(buffDist); % STD(i) = std(buffDist,0); % RMSE(i) = std(buffDist,1); % ERROR(i) = 265.5 - MEAN(i); % % end % % figure % plot(1:totalFrame, MEAN(startFrame:endFrame), 'b-o', 'LineWidth', 2); % xlabel('Frames','FontSize',16); % ylabel('Diameter(mm)','FontSize',16); % set(gca,'FontSize',14); % xlim([1, totalFrame]);