From 4e213673f7b5bdd653adc604d7dea3a72a8c5a36 Mon Sep 17 00:00:00 2001 From: "Zhenqiang.Ying" Date: Thu, 15 Oct 2015 11:43:59 +0800 Subject: [PATCH] release ISM2015 --- Contents.m | 39 -- ICASSP2016.m | 455 --------------------- ISM2015.m | 4 +- README | 25 ++ my_exp_util/foreach_input_do.m | 37 -- my_exp_util/maxfig.m | 53 --- my_exp_util/slidevar.m | 37 -- my_img_util/Plot.m | 32 -- my_img_util/bwmaxconnected.m | 12 - my_img_util/distanceP2L.m | 31 -- my_img_util/foreach_frame_do.m | 75 ---- my_img_util/getChannel.m | 24 -- my_img_util/im2gray.m | 12 - my_img_util/imdump.m | 37 +- my_img_util/imshowblob.m | 1 - my_img_util/imshowcolor.m | 74 ---- my_img_util/imshowedge.m | 77 ---- my_img_util/imshowforegrond.m | 18 - my_img_util/imshowhough.m | 35 -- my_img_util/imshowlight.m | 73 ---- my_img_util/imshowsky.m | 441 -------------------- my_img_util/linemeetpoint.m | 35 -- my_img_util/plotflow.m | 34 -- my_img_util/plotline.m | 5 - my_img_util/plotobj.m | 44 -- my_img_util/plotpoint.m | 34 -- my_img_util/recover3dlayout.m | 37 -- my_img_util/selplot.m | 40 -- my_img_util/subplott.m | 31 -- my_vehicle_vision_util/VehicleVision.m | 83 ---- my_vehicle_vision_util/im2birdview.m | 56 --- my_vehicle_vision_util/im2vanishingpoint.m | 88 ---- my_vehicle_vision_util/vvColorFeature.m | 63 --- my_vehicle_vision_util/vvCreateMask.m | 37 -- my_vehicle_vision_util/vvDirectionFilter.m | 92 ----- my_vehicle_vision_util/vvGetFeature.m | 85 ---- my_vehicle_vision_util/vvGetLaneMarking.m | 150 ------- my_vehicle_vision_util/vvGetLine.m | 58 --- my_vehicle_vision_util/vvGetRoadFace.m | 278 ------------- my_vehicle_vision_util/vvGetVp.m | 89 ---- my_vehicle_vision_util/vvMarkFeature.m | 102 ----- my_vehicle_vision_util/vvPreprocess.m | 60 --- my_vehicle_vision_util/vvRowFilter.m | 78 ---- my_vehicle_vision_util/vvRowFilterTest.m | 46 --- my_vehicle_vision_util/vvSegBound.m | 172 -------- 45 files changed, 50 insertions(+), 3339 deletions(-) delete mode 100644 Contents.m delete mode 100644 ICASSP2016.m create mode 100644 README delete mode 100644 my_exp_util/foreach_input_do.m delete mode 100644 my_exp_util/maxfig.m delete mode 100644 my_exp_util/slidevar.m delete mode 100644 my_img_util/Plot.m delete mode 100644 my_img_util/bwmaxconnected.m delete mode 100644 my_img_util/distanceP2L.m delete mode 100644 my_img_util/foreach_frame_do.m delete mode 100644 my_img_util/getChannel.m delete mode 100644 my_img_util/im2gray.m delete mode 100644 my_img_util/imshowblob.m delete mode 100644 my_img_util/imshowcolor.m delete mode 100644 my_img_util/imshowedge.m delete mode 100644 my_img_util/imshowforegrond.m delete mode 100644 my_img_util/imshowhough.m delete mode 100644 my_img_util/imshowlight.m delete mode 100644 my_img_util/imshowsky.m delete mode 100644 my_img_util/linemeetpoint.m delete mode 100644 my_img_util/plotflow.m delete mode 100644 my_img_util/plotline.m delete mode 100644 my_img_util/plotobj.m delete mode 100644 my_img_util/plotpoint.m delete mode 100644 my_img_util/recover3dlayout.m delete mode 100644 my_img_util/selplot.m delete mode 100644 my_img_util/subplott.m delete mode 100644 my_vehicle_vision_util/VehicleVision.m delete mode 100644 my_vehicle_vision_util/im2birdview.m delete mode 100644 my_vehicle_vision_util/im2vanishingpoint.m delete mode 100644 my_vehicle_vision_util/vvColorFeature.m delete mode 100644 my_vehicle_vision_util/vvCreateMask.m delete mode 100644 my_vehicle_vision_util/vvDirectionFilter.m delete mode 100644 my_vehicle_vision_util/vvGetFeature.m delete mode 100644 my_vehicle_vision_util/vvGetLaneMarking.m delete mode 100644 my_vehicle_vision_util/vvGetLine.m delete mode 100644 my_vehicle_vision_util/vvGetRoadFace.m delete mode 100644 my_vehicle_vision_util/vvGetVp.m delete mode 100644 my_vehicle_vision_util/vvMarkFeature.m delete mode 100644 my_vehicle_vision_util/vvPreprocess.m delete mode 100644 my_vehicle_vision_util/vvRowFilter.m delete mode 100644 my_vehicle_vision_util/vvRowFilterTest.m delete mode 100644 my_vehicle_vision_util/vvSegBound.m diff --git a/Contents.m b/Contents.m deleted file mode 100644 index d4e7bc8..0000000 --- a/Contents.m +++ /dev/null @@ -1,39 +0,0 @@ -% Vehicle Vision System Toolbox -% Version 1.0 2015-6-19 -% -% M-files about the Vehicle Perception project, by -% Zhenqiang Ying, 2015. -% https://github.com/baidut/OpenVehicleVision -% -% Release information. -% Readme - Information about current and previous versions. -% -% My Exp Util -% foreach_file_do - Batch files -% foreach_input_do - Traversing parameters for testing -% str2files - Output files matching the input string with wildcard -% out2fifo - Output to a First In First Out buffer -% slidevar - Controlling a variable with a slidebar -% maxfig - Maximized figure -% -% My img Util -% foreach_frame_do - Traversing frames for image processing -% getChannel - Get channels of a color image -% linemeetpoint - Get line intersection -% plotline - plot a line by two end points -% subplott - plot images without spacing -% im2gray - Output the grayscale version of an input image -% implot - Facilitate plotting many images -% imshowcolor - Perform color space conversion -% imshowedge - Perform edge detection -% imshowhough - Perform Hough transform -% imshowlight - Perform thresholding -% imshowblob - -% imshowforeground - -% imshowsky - -% -% My Vehicle Vison Util -% vvPreprocess - -% vvGetFeature - -% vvGetRoadFace - -% vvGetline - \ No newline at end of file diff --git a/ICASSP2016.m b/ICASSP2016.m deleted file mode 100644 index 515528c..0000000 --- a/ICASSP2016.m +++ /dev/null @@ -1,455 +0,0 @@ -function ICASSP2016(files, isvideo, istracking) -% show results: -% foreach_file_do('F:\Documents\MATLAB\capture\ICASSP\results\*.jpg', @imshow); -% show dataset: -% foreach_file_do('F:\dataset\SLD2011\dataset3\sequence\*.jpg', @imshow); - - -% function from OpenVehiclelVision: getChannel, implot, imdump, plotpoint, plotobj - -% the main framework, the modules which can be improved are listed as sub function. - - if ~istracking - if ~isvideo - % test files, no tracking - foreach_file_do(files, @(file) {figure('NumberTitle', 'off', 'Name', file), roadDetection(imread(file))} ); - else - % test a video, no tracking - foreach_frame_do(files, @(file) roadDetection(file)); - end - else % tracking - if ~isvideo - % test files, tracking - ok = 0; - index = 1; - for i = index : length(files) - filename = files{index}; - RawImg = imread(filename); - - h = figure('NumberTitle', 'off', 'Name', filename); - - if ok - [ok, trackinfo, learninfo] = roadDetection(RawImg, trackinfo, learninfo); - else - [ok, trackinfo, learninfo] = roadDetection(RawImg); - end - index = index + 1; - end - else - % to be added - end - end -end - - -function [ok, trackinfo, learninfo] = roadDetection(RawImg, trackinfo, learninfo) - %% set output fold. -global dumppathstr; - dumppathstr = 'F:/Documents/MATLAB/Temp/'; - - %% road detection - [nRow, nCol, ~] = size(RawImg); - - %% Preprocessing - deblock - BlurImg = imgaussfilt(RawImg, 2); - - if nargin > 1 - % trackinfo is provided - vanishingPoint = trackinfo.vanishingPoint; - endRowPointL = trackinfo.endRowPointL; - endRowPointR = trackinfo.endRowPointR; - ratioLaneMark = trackinfo.ratioLaneMark; - - if nargin > 2 - % RoadFaceClassifier = learninfo.RoadFaceClassifier; - end - else - vanishingPoint = [nCol/2, nRow/3]; % nRow/4 - % endRowPointL = [0, nRow]; - % endRowPointR = [nCol, nRow]; - end - - nColSplit = floor(vanishingPoint(1)); - nRowSplit = floor(vanishingPoint(2)); - nHorizon = floor(vanishingPoint(2)); - - if exist('endRowPointL', 'var') - A = floor(vanishingPoint + endRowPointL)/2 + [0, -nHorizon+1]; - B = floor(vanishingPoint + endRowPointR)/2 + [0, -nHorizon+1]; - - MaskRoadFace = false(nRow-nHorizon+1, nCol); - MaskRoadFace(A(2):end, A(1):B(1)) = true; - MaskRoadBound = false(nRow-nHorizon+1, nCol); - MaskRoadBound(1:A(2)-1, [1:A(1),B(1):end]) = true; % -1 to avoid overlapping - - % imseggeodesic RGB image - [Label, ~] = imseggeodesic(RawImg(nHorizon:end,:,:),MaskRoadFace,MaskRoadBound); - RoadBound = (Label == 2); % label 1 - RoadFace, 2 - RoadBound - roadSegL = RoadBound(:, 1:nColSplit); - roadSegR = RoadBound(:, nColSplit+1:end); - - else - - featureMap = featureExtractionByS2(BlurImg); % featureExtractionByRpGm2B - roadSegL = segmentByOtsu(featureMap(nRowSplit:end, 1:nColSplit,:)); - roadSegR = segmentByOtsu(featureMap(nRowSplit:end, nColSplit+1:end,:)); - -% roadSegL = isBound(RawImg(nRowSplit:end, 1:nColSplit,:)); -% roadSegR = isBound(RawImg(nRowSplit:end, nColSplit+1:end,:)); - end - - roadBoundPointsL = boundPoints(roadSegL, true); - roadBoundPointsR = boundPoints(roadSegR, false); - - %% dump results of stage 1. -% roadBoundPointsCandidate = zeros(nRow, nCol); -% roadBoundPointsCandidate(nRowSplit:end,:) = [roadBoundPointsCandidateL, roadBoundPointsCandidateR]; - - roadBoundPoints = zeros(nRow, nCol); - roadBoundPoints(nRowSplit:end,:) = [roadBoundPointsL, roadBoundPointsR]; - - roadSeg = zeros(nRow, nCol); - roadSeg(nRowSplit:end, :) = [roadSegL, roadSegR]; - -% implot(RawImg, BlurImg, featureMap, roadSeg); -% selplot(1); hold on; -% [X, Y] = find(roadBoundPoints == 1); -% plot(Y, X,'r*'); - imdump(featureMap, roadSeg, roadBoundPoints); - - - %% Next Stage - roadBoundAngleMin = 30; - roadBoundAngleMax = 75; - - if nargin == 1 % no tracking - roadBoundLineL = fitStraightLineByHough(roadBoundPoints, roadBoundAngleMin:roadBoundAngleMax); % 0:89 - roadBoundLineR = fitStraightLineByHough(roadBoundPoints, -roadBoundAngleMax:roadBoundAngleMin); % -89:0 - else - roadBoundLineL = fitStraightLineByHough(roadBoundPointsL, roadBoundAngleMin:roadBoundAngleMax); % 0:89 - roadBoundLineR = fitStraightLineByHough(roadBoundPointsR, -roadBoundAngleMax:roadBoundAngleMin); % -89:0 - - roadBoundLineL.move([0, nRowSplit]); - roadBoundLineR.move([nColSplit, nRowSplit]); - end - - endRowPointL = [roadBoundLineL.row(nRow), nRow]; - endRowPointR = [roadBoundLineR.row(nRow), nRow]; - - vanishingPoint = roadBoundLineL.cross(roadBoundLineR); - nHorizon = floor(vanishingPoint(2)); - horizonLine = LineObj([1, nHorizon], [nCol, nHorizon]); - - ratioNearField = 0.6; % r% of roadface will be considered as near field. - pointLeftTop = vanishingPoint*ratioNearField + endRowPointL*(1-ratioNearField); - pointRightTop = vanishingPoint*ratioNearField + endRowPointR*(1-ratioNearField); - movingPoints = [pointLeftTop; pointRightTop; endRowPointR; endRowPointL]; - - nOutCol = 80; nOutRow = 60; % size of map where the lane-making points locate in one column. - fixedPoints = [1, 1; nOutCol,1; nOutCol, nOutRow; 1,nOutRow]; - tform = fitgeotrans(movingPoints, fixedPoints, 'projective'); - - GrayImg = RawImg(:,:,1); - RoadFace_ROI = imwarp(GrayImg, tform, 'OutputView', imref2d([nOutRow, nOutCol]), 'FillValues', 0.8*median(GrayImg(nRow,:))); - - %% plots -% MovingPointsSelection = figure;imshow(RawImg);impoly(gca, movingPoints); -% axis auto;%axis([endRowPointL(1) endRowPointR(1) 1 nRow]); -% saveeps(MovingPointsSelection, RoadFace_ROI); - - %% - % if track on, then just focus the near field of last detected lane-marking. - multiLaneMode = false; - - if ~multiLaneMode - if ~exist('ratioLaneMark', 'var') - ratioLaneMark = 0.5; - halfSearchRange = nOutCol/4; - else - halfSearchRange = 5; - end - leftLimit = floor(ratioLaneMark*nOutCol-halfSearchRange); - rightLimit = floor(ratioLaneMark*nOutCol+halfSearchRange); - LaneMark = laneMarkFilter(RoadFace_ROI); - LaneMark(:,[1:leftLimit,rightLimit:end]) = 0; - else - LaneMark = laneMarkFilter(RoadFace_ROI); - end - - ColPixelSum = sum(LaneMark, 1); - [~, index] = max(ColPixelSum); - - ratioLaneMark = index / nOutCol; - - endRowPointM = [(1-ratioLaneMark) * roadBoundLineL.row(nRow) + ratioLaneMark * roadBoundLineR.row(nRow), nRow]; - roadMidLine = LineObj(vanishingPoint, endRowPointM); - - %% plot results. - % in detail - BirdView = imwarp(RawImg, tform); - nOutCol2 = 600; nOutRow2 = 450; - fixedPoints = [1, 1; nOutCol2,1; nOutCol2, nOutRow2; 1,nOutRow2]; - tform = fitgeotrans(movingPoints, fixedPoints, 'projective'); - - RoadFace_All = imwarp(RawImg, tform, 'OutputView', imref2d([6*nOutRow2, nOutCol2],[1 nOutCol2], [-5*nOutRow2, nOutRow2]) ); % 'OutputView', imref2d([nOutRow, nOutCol]) - % imref2d([nOutRow, nOutCol],[1 4*nOutRow],[1 nOutCol]) - % imref2d(imageSize,xWorldLimits,yWorldLimits) - - - % GroundTruth = imread('RIMG00021.pgm'); - % GTBirdView = imwarp(GroundTruth, tform); - - dumpFigureInPaper; - debugout; - - %% plot(for debug). - function dumpFigureInPaper() - % note that imshow return a handle of image while implot return a - % handle of figure. - figure;h1 = implot(RawImg);title('');hold on; % FeatureMap - - l1 = LineObj(vanishingPoint, endRowPointL); - l2 = LineObj(vanishingPoint, endRowPointR); - l1.plot('r','LineWidth', 8); - l2.plot('g','LineWidth', 8); - roadMidLine.plot('b','LineWidth', 8); - figure; h2 = implot(imoverlay(RoadFace_ROI, LaneMark, [255, 255, 0])); - saveeps(RawImg, h1, h2); - figure; boundpoints = implot(RawImg);title(''); - hold on; - plotpoint(roadBoundPoints); - figure; boundaries = implot(RawImg);title(''); - l1.plot('r','LineWidth', 8); - l2.plot('g','LineWidth', 8); - saveeps(featureMap, roadSeg, boundpoints, boundaries); - end - - function debugout() - subplot(2,3,1); - imshow(RawImg);title('Raw image');hold on; - l1 = LineObj(vanishingPoint, endRowPointL); - l2 = LineObj(vanishingPoint, endRowPointR); - l1.plot('r'); - l2.plot('g'); - roadMidLine.plot('b'); - subplot(2,3,2); - imshow(RoadFace_ROI);title('Near field roadface'); - - subplot(2,3,[3 6]); - imshow(RoadFace_All);title('Extract roadface'); - - subplot(2,3,4); - imshow(imoverlay(featureMap, roadSeg, [255, 255, 0])); - title('Detection Result');hold on; - plotpoint(roadBoundPoints, vanishingPoint, endRowPointL, endRowPointR); - plotobj(horizonLine, roadBoundLineL, roadBoundLineR, roadMidLine); - - subplot(2,3,5); - imshow(imoverlay(RoadFace_ROI, LaneMark, [255, 255, 0])); - title('Lane marks'); - hold on; plot(1:nOutCol, ColPixelSum); - - %maxfig; - set(gcf,'outerposition',get(0,'screensize')); - %set(gcf,'PaperUnits','centimeters','PaperPosition',[0 0 30 20]); % [0 0 30 20] - - % write results to file. - % imdump(RoadFace_ROI, BirdView, RoadFace_All); - % %saveeps; - % h = gcf; - % [~,name,~] = fileparts(h.Name); - % % saveas(h, ['F:\Documents\MATLAB\Temp/', name, '.png']); cannot handle - % % maximized figure. - % print(name, '-djpeg', '-r300'); % ['F:\Documents\MATLAB\Temp/' - % %close(h); - end - %% check if the detection result is ok. - % if not, reject the trackinfo and redetect. - % if redetect failed, use last detection result. - ok = true; - if nargout > 1 - % trackinfo - trackinfo = struct; - trackinfo.vanishingPoint = vanishingPoint; - trackinfo.ratioLaneMark = ratioLaneMark; - trackinfo.endRowPointL = endRowPointL; - trackinfo.endRowPointR = endRowPointR; - - if nargout > 2 - learninfo = 'learninfo: not support now'; - % learninfo.RoadFaceClassifier = RoadFaceClassifier; - end - end - - - - % nested function - - function data = computeFeatureVector() - % resize the data for training - nRow2 = nRow-nHorizon; - nFeature = 2; - data = zeros( nRow2*nCol, nFeature); % 1 index, num of training pixels. % 4 features. - % r, c, v, s2 - % data(:, 3) = repmat(1:nRow2, 1, nCol); - % data(:, 4) = repmat((1:nCol)', nRow2, 1); - f1 = featureMap(nHorizon+1:end,:); % S2 component - f2 = RawImg(nHorizon+1:end,:,2); % G component - data = cat(nFeature, f1(:), double(f2(:))); - end - % end nested function -end - -% independent function - -function BW_Filtered = isBound(RawImg) -% check if a pixel is boundary point - [RGB_R, RGB_G, RGB_B] = getChannel(RawImg); - RGB_max = max(max(RGB_R, RGB_G) , RGB_B); - FeatureMap = double(RGB_max - RGB_B) ./ double(RGB_max + 1); - -% BW = vvCreateMask(RawImg); - I = rgb2hsv(RawImg); - channel1Min = 0.828; - channel1Max = 0.469; - % BW = ( (I(:,:,1) >= channel1Min) | (I(:,:,1) <= channel1Max) ) & ... - BW = (FeatureMap >= 0.1 +graythresh(FeatureMap)) ; - - BW_imclose = imclose(BW, strel('square',3)); %imdilate imclose imopen - BW_areaopen = bwareaopen(BW_imclose, 100); % 60 % size should be adaptive - BW_Filtered = BW_areaopen; - return; - - Seg = segment(FeatureMap); -%% Refine boundary points -% Remove shadows - Shadow = RGB_B == RGB_max; - BW = Seg .* ~Shadow; - imdump(Seg, BW, Shadow); -end - -function FeatureMap = featureExtractionByS2(Rgb) - [RGB_R, RGB_G, RGB_B] = getChannel(Rgb); - % RGB_min = min(min(RGB_R, RGB_G) , RGB_B); - RGB_max = max(max(RGB_R, RGB_G) , RGB_B); - FeatureMap = double(RGB_max - RGB_B) ./ double(RGB_max + 1); -end - -function FeatureMap = featureExtractionByRpGm2B(Rgb) - [RGB_R, RGB_G, RGB_B] = getChannel(Rgb); - FeatureMap = RGB_R + RGB_G - 2 * RGB_B; -end - -function BW_Filtered = segment(Gray) - BW = Gray > 2 * mean(Gray(:)); % 2.5 * mean(Gray(end,:));0.15 * max(Gray(:));0.3 0.2 - %BW_imclose = imclose(BW, strel('square',3)); %imdilate imclose imopen - BW_areaopen = bwareaopen(BW, 200, 4); % 60 - BW_Filtered = BW_areaopen; -end - -function BW_Filtered = segmentByOtsu(GrayImg) - BW = im2bw(GrayImg, graythresh(GrayImg)+0.1); % 0.06 + - %BW_imclose = imclose(BW, strel('square', 5)); %imdilate imclose imopen - BW_areaopen = bwareaopen(BW, 230, 4); - BW_Filtered = BW_areaopen; -end - -function BW_Filtered = segmentByFixedThresh(GrayImg) - GrayImg = mat2gray(GrayImg); % 0 - 1 - BW = (GrayImg < 0.58 ) .* (GrayImg > 0.52) ; - %BW_imclose = imclose(BW, strel('square', 5)); %imdilate imclose imopen - BW_areaopen = bwareaopen(BW, 230, 4); - BW_Filtered = BW_areaopen; -end - -function BW = segmentByEdge(GrayImg, isleft) - H = [ 1, 0, 0, 0, -1; - 1, 0, 0, 0, -1; - 4, 2, 0, -2, -4; - 1, 0, 0, 0, -1; - 1, 0, 0, 0, -1]; - - if ~isleft - H = -H; - end - EdgeFeature = imfilter(GrayImg,H,'replicate'); - BW = im2bw(EdgeFeature,graythresh(EdgeFeature)); - imdump(BW,EdgeFeature); -end - -function Boundary = boundPoints(BW, isleft) - [nRow, nCol] = size(BW); - Candidate = zeros(nRow, nCol); - Boundary = zeros(nRow, nCol); - - for c = 1 : nCol % for each column - r = find(BW(:,c),1,'last');% up-down scan - Candidate(r, c) = 1; - end - - if isleft - for r = 1 : nRow - c = find(Candidate(r,:),1,'last'); - Boundary(r, c) = 1; - end - else - for r = 1 : nRow - c = find(Candidate(r,:),1,'first'); - Boundary(r, c) = 1; - end - end - -end - -function line = fitStraightLineByHough(BW, Theta) - %Hough Transform - [H,theta,rho] = hough(BW, 'Theta', Theta); - - % Finding the Hough peaks - P = houghpeaks(H, 1); - %x = theta(P(:,2)); - %y = rho(P(:,1)); - - %Fill the gaps of Edges and set the Minimum length of a line - lines = houghlines(BW,theta,rho,P, 'MinLength',10, 'FillGap',570); - - if length(lines) > 1 - lines = lines(1); - end - - if length(lines) ~= 1 - error('Fail in fitLine.'); - end - - % line = LineObj([lines.point1(2), lines.point1(1)], [lines.point2(2), lines.point2(1)]); - line = LineObj(lines.point1, lines.point2); -end - -function line = fitStraightLineByRansac(BW, Theta) -% 直接采用边界点进行Ransac直线?效果很差 -% ?支持曲线提取 - [X,Y] = find(BW == 1); - pts = [X';Y']; - iterNum = 300; - thDist = 2; - thInlrRatio = .1; - [t,r] = ransac(pts,iterNum,thDist,thInlrRatio); - k1 = -tan(t); - b1 = r/cos(t); - Y = k1*X+b1; - line = LineObj([X(1), Y(1)], [X(end), Y(end)]); -end - -function laneMark = laneMarkFilter(GrayImg) - H = [-1, 0, 2, 0, -1; - -1, 0, 2, 0, -1; - -1, 0, 2, 0, -1; - -1, 0, 2, 0, -1; - -1, 0, 2, 0, -1; - -1, 0, 2, 0, -1; - -1, 0, 2, 0, -1]; - Filtered = imfilter(GrayImg,H,'replicate'); % & mask - BW = Filtered > 0.8*max(Filtered(:)); - laneMark = bwareaopen(BW,18,4); - saveeps(Filtered, BW, laneMark); -end \ No newline at end of file diff --git a/ISM2015.m b/ISM2015.m index b88ee9b..44f89ed 100644 --- a/ISM2015.m +++ b/ISM2015.m @@ -12,7 +12,7 @@ mkdir('results'); dumpPath = '.\results'; dumpLevel = 1; -saveEps = true;%false; +saveEps = false; path = 'F:\Documents\MATLAB\dataset\roma\'; ext = 'jpg'; @@ -41,7 +41,7 @@ close(fig); end -%% +%% generate 'evaluation.tex' for buiding pdf of evaluation results. text = evalc('gentex'); fid = fopen('results/evaluation.tex','w'); fprintf(fid, '%s', text); diff --git a/README b/README new file mode 100644 index 0000000..c6ef9f5 --- /dev/null +++ b/README @@ -0,0 +1,25 @@ +README +------ + +This codebase implements An Illumination-Robust Approach for Feature-Based Road Detection. + +This code is provided "as-is" with no warranty or explicit support. It is made available for personal and academic use ONLY. Any commercial use of this code without explicit written consent of the authors is strictly prohibited. Use of this in academic publications should cite: + +"An Illumination-Robust Approach for Feature-Based Road Detection" by Zhenqiang Ying, Ge Li & Guozhen Tan. In IEEE International Symposium on Multimedia, ISM 2015. + +This code is copyright Zhenqiang Ying, Ge Li & Guozhen Tan, 2015. + +Questions or comments regarding this code should be directed to Zhenqiang YING (yingzhenqiang@gmail.com). + + +Getting Started +--------------- + +Download roma dataset from http://www.lcpc.fr/english/products/image- databases/article/roma-road-markings-1817 . + +Download code from https://github.com/baidut/OpenVehicleVision/releases/tag/ism2015 . + +Open file 'ISM2015.m' and specify your folder containing roma dataset. +path = 'F:\Documents\MATLAB\dataset\roma\'; % Modify it! + +run 'ISM2015.m' in Matlab. \ No newline at end of file diff --git a/my_exp_util/foreach_input_do.m b/my_exp_util/foreach_input_do.m deleted file mode 100644 index 38a89c5..0000000 --- a/my_exp_util/foreach_input_do.m +++ /dev/null @@ -1,37 +0,0 @@ -function h = foreach_input_do(test, func, varargin) -% USAGE: - % foreach_input_do([1:1:2], @edge, I, 'sobel', [], 'both') - % tmp('hello',[],1,[1:2],'') -% varargin{var} -% 参数必须装在元胞里面 -% foreach_input_do({[1:1:2];{'horizontal', 'vertical', 'both'}} ... - % @edge, I, 'sobel', [], ''); -% {Sobel, Roberts, LoG, Canny, Prewitt} = foreach_input_do({'sobel', 'roberts', 'log', 'canny', 'prewitt'} ,@edge, I, ''); -% implot(I, Sobel, Roberts, LoG, Canny, Prewitt); -% foreach_input_do([1:2:8] ,@disp, []); -% foreach_input_do([1:2:8] ,@disp); -% h 为函数输出 - -if nargin < 3 - varargin = {[]}; -end - -notgiven = cellfun(@isempty, varargin); -[n_param, n_test] = size(test); -if sum(notgiven) ~= n_param - error('invalid inputs.'); -end - -if n_param == 1 - h = cell(1, n_test); % 需要初始化 - pos = find(notgiven == 1); - idx = 1; - for m = test - varargin{pos} = char(m); % m为cell 不转为char会出错,无法赋值 - h{idx} = func(varargin{:}); % disp函数无返回值 - idx = idx + 1; - % subplot(r, c, i); 此处不提供绘图功能 - end - %implot(h{:}); %没有title -% n_param == 2 & n_test == 1 % cell -end \ No newline at end of file diff --git a/my_exp_util/maxfig.m b/my_exp_util/maxfig.m deleted file mode 100644 index 524b906..0000000 --- a/my_exp_util/maxfig.m +++ /dev/null @@ -1,53 +0,0 @@ -function maxfig(varargin) -%MAXFIG Maximized figure -% USAGE: -% MAXFIG; -% MAXFIG(fig1, fig2); -if nargin == 0 - maxfig(gcf); -else - for i = 1: nargin - fig = varargin{i}; - if verLessThan('matlab', '7.11') - jframe=getJFrame(fig);jframe.setMaximized(1); - % getJFrame 在R2012a适用,R2015a出错,错误信息如下 - % Undefined function 'abs' for input arguments of type 'matlab.ui.Figure'. - else - scrsz = get(0,'ScreenSize'); - set(fig,'Position',scrsz); - % see more http://blog.163.com/yinhexiwen@126/blog/static/6404826620122942057214/ - end - end -end - -function JFrame = getJFrame(hfig) -%GETJFRAME converts MATLAB figure handle to JAVA object, -%which provides methods like setMaximized, setMinimized and setAlwaysOnTop. -% USAGE: -% h=figure; -% jframe = getJFrame(gcf); % Alternative: jframe = getJFrame(h); -% jframe.setMaximized(1); -% jframe.setMinimized(1); -% jframe.setAlwaysOnTop(1); - -error(nargchk(1,1,nargin)); -if ~ishandle(hfig) && ~isequal(get(hfig,'Type'),'figure') - error('The input argument must be a Figure handle.'); -end -mde = com.mathworks.mde.desk.MLDesktop.getInstance; -if isequal(get(hfig,'NumberTitle'),'off') && isempty(get(hfig,'Name')) - figTag = 'junziyang'; %Name the figure temporarily - set(hfig,'Name',figTag); -elseif isequal(get(hfig,'NumberTitle'),'on') && isempty(get(hfig,'Name')) - figTag = ['Figure ',num2str(hfig)]; -elseif isequal(get(hfig,'NumberTitle'),'off') && ~isempty(get(hfig,'Name')) - figTag = get(hfig,'Name'); -else - figTag = ['Figure ',num2str(hfig),': ',get(hfig,'Name')]; -end -drawnow %Update figure window -jfig = mde.getClient(figTag); %Get the underlying JAVA object of the figure. -JFrame = jfig.getRootPane.getParent(); -if isequal(get(hfig,'Name'),'junziyang') - set(hfig,'Name',''); %Delete the temporary figure name -end diff --git a/my_exp_util/slidevar.m b/my_exp_util/slidevar.m deleted file mode 100644 index 380410f..0000000 --- a/my_exp_util/slidevar.m +++ /dev/null @@ -1,37 +0,0 @@ -function h=slidevar(varname,span) -%SLIDEVAR controlling a variable with a slidebar -% http://www.mathworks.com/matlabcentral/newsreader/view_thread/28286 - -if nargin==2 - h = figure('pos',[300 300 300 80],... - 'menubar','none',... - 'numbertitle','off',... - 'name',['Variable: ' varname]); - - hs = uicontrol(h,... - 'style','slider',... - 'pos',[10 40 280 20],... - 'min',span(1),... - 'max',span(2),... - 'value',span(1),... - 'callback',@sliderupdate,... - 'tag',varname); - - uicontrol(h,... - 'style','text',... - 'pos',[10 10 280 20],... - 'tag',['text_' varname],... - 'string',num2str(span(1))) - - if nargout==0 - clear h - end -end - -% ------------------- -function sliderupdate(varargin) - -ht = findobj(gcbf, 'style','text'); -v = get(varargin{1},'value'); -set(ht, 'string', num2str(v)) -assignin('base', get(varargin{1},'tag'), v) \ No newline at end of file diff --git a/my_img_util/Plot.m b/my_img_util/Plot.m deleted file mode 100644 index 7784591..0000000 --- a/my_img_util/Plot.m +++ /dev/null @@ -1,32 +0,0 @@ -classdef Plot - -% TODO: 标注多个对象,颜色不同,并且添加title为变量名称 -% 需要先初始化画图位置,默认为gca -% draw = Plot(); -% draw.points(O,P,Q) -% draw.lines(l1,l2) - - %% Public properties - properties (GetAccess = public, SetAccess = private) - end - - %% Public methods - methods (Access = public) - - function obj = Plot(var) - end - - function ratio = plotLane(obj) - end - - function [pointsM, labeled] = drawLine(obj, ratio) - end - - end% methods -end% classdef - -% Matlab存无白边的fig -% print('result.eps','-depsc') -% print -depsc2 filename.eps -% 有白边 -% saveas(gca,'meanshape.bmp','bmp'); \ No newline at end of file diff --git a/my_img_util/bwmaxconnected.m b/my_img_util/bwmaxconnected.m deleted file mode 100644 index 610c516..0000000 --- a/my_img_util/bwmaxconnected.m +++ /dev/null @@ -1,12 +0,0 @@ -% 提取最大联通分量 - -% 先腐蚀膨胀一下,去除杂点 也可以在前面灰度膨胀 -% 找出最大的连通分量即为路面区域。 或采用膨胀腐蚀算法消去噪点 -% [L, num] = bwlabel(SaturateMap, 4); % TODO 4连通对比 -% x=zeros(1,num); -% for idx=1:num -% x(idx)=sum(sum(L == idx)); -% end -% [m, idx] = max(x); -% Connected = (L == idx); -% DLD提取的为内部,而Canny为边界,求点乘就没有了。。。 \ No newline at end of file diff --git a/my_img_util/distanceP2L.m b/my_img_util/distanceP2L.m deleted file mode 100644 index e634488..0000000 --- a/my_img_util/distanceP2L.m +++ /dev/null @@ -1,31 +0,0 @@ -function d = distanceP2L(P, Q1, Q2) % Point, LinePoint1, LinePoint2 -% P-点坐标;Q1, Q2线上两点坐标 - -if length(P) == 3 - % 三维空间: - d = norm(cross(Q2-Q1,P-Q1))/norm(Q2-Q1); -elseif length(P) == 2 - % 二维空间 - if (isrow(Q1) && isrow(Q2)) - d = abs(det([Q2-Q1;P-Q1]))/norm(Q2-Q1); % 坐标为行向量 - elseif (iscolumn(Q1) && iscolumn(Q2)) - d = abs(det([Q2-Q1,P-Q1]))/norm(Q2-Q1); % 坐标为列向量 - else - error('Q1/Q2 should be a vector.'); - end -end - - -% % 测试 -% Q1 = [33, 12]; -% Q2 = [13, 45]; -% for ii = 1:100 -% for jj = 1:100 -% P = [ii, jj]; -% MAP(ii, jj) = distanceP2L(P, Q1, Q2); -% end -% end -% implot(MAP); -% hold on; -% plot(Q1(2), Q1(1), 'r*'); -% plot(Q2(2), Q2(1), 'r*'); \ No newline at end of file diff --git a/my_img_util/foreach_frame_do.m b/my_img_util/foreach_frame_do.m deleted file mode 100644 index 8a3bd39..0000000 --- a/my_img_util/foreach_frame_do.m +++ /dev/null @@ -1,75 +0,0 @@ -function ok = foreach_frame_do(file, func) -%FOREACH_FRAME_DO batch processing each frame of video -% USAGE: -% foreach_frame_do('./ronda42_mpeg4.avi', @imshow) -% foreach_frame_do('./ronda42_mpeg4.avi', @(frame, index) imwrite(frame, num2str(index, 'ronda42_mpeg4/%05d.jpg'))) -% foreach_frame_do('videos/road.avi', @imdetectlane) -% Probelme to be solved(7.14.0.739 (R2012a)) -% Error using VideoReader/init (line 447) -% The file requires the following codec(s) to be installed on your system: - % H264 - -if verLessThan('matlab', '7.11') -% R2010a(7.10) Functions and Function Elements Being Removed [includes aviread] -% R2010b(7.11) mmreader Renamed VideoReader -% view the release notes page for detail http://www.mathworks.com/help/matlab/release-notes-older.html - - mov = mmreader(file); - frames = read(mov); - for i = 1 : size(frames, 4) - image = frames(:,:,:,i); - func(image, varargin{:}); - end -else - vidObj = VideoReader(file); - while hasFrame(vidObj) - vidFrame = readFrame(vidObj); - func(vidFrame, index); - end -end - - -% MMREADER has been removed. Use VIDEOREADER instead. - -% VERSION - -% For example: -% >> version -% 7.14.0.739 (R2012a) -% >> verLessThan('matlab', '7.15') -% 1 -% >> verLessThan('matlab', '7.14') -% 0 - -% Here are the MCR and MATLAB Compiler versions for some releases of MATLAB: - % ---------------------------------------------- - % MATLAB | MATLAB | MATLAB | - % Release | Component | Compiler | - % | Runtime (MCR) | Version | - % ---------------------------------------------- - % R14 (7.0) | 7.0 | 4.0 | - % R14SP1 (7.0.1) | 7.1 | 4.1 | - % R14SP2 (7.0.4) | 7.2 | 4.2 | - % R14SP3 (7.1) | 7.3 | 4.3 | - % R2006a (7.2) | 7.4 | 4.4 | - % R2006b (7.3) | 7.5 | 4.5 | - % R2007a (7.4) | 7.6 | 4.6 | - % R2007b (7.5) | 7.7 | 4.7 | - % R2008a (7.6) | 7.8 | 4.8 | - % R2008b (7.7) | 7.9 | 4.9 | - % R2009a (7.8) | 7.10 | 4.10 | - % R2009b (7.9) | 7.11 | 4.11 | - % R2009bSP1 (7.9.1) | 7.12 | 4.12 | - % R2010a (7.10) | 7.13 | 4.13 | - % R2010b(7.11) | 7.14 | 4.14 | - % R2010bSP1 (7.11.1)| 7.14.1 | 4.14.1 | - % R2010bSP2 (7.11.2)| 7.14.2 | 4.14.1 | - % R2011a (7.12) | 7.15 | 4.15 | - % R2011b (7.13) | 7.16 | 4.16 | - % R2012a (7.14) | 7.17 | 4.17 | - % R2012b (8.0) | 8.0 | 4.18 | - % R2013a (8.1) | 8.1 | 4.18.1 | - % R2013b (8.2) | 8.2 | 5.0 | - % R2014a (8.3) | 8.3 | 5.1 | - % R2014b (8.4) | 8.4 | 5.2 | - % ---------------------------------------------- \ No newline at end of file diff --git a/my_img_util/getChannel.m b/my_img_util/getChannel.m deleted file mode 100644 index e9aad0c..0000000 --- a/my_img_util/getChannel.m +++ /dev/null @@ -1,24 +0,0 @@ -function [varargout] = getChannel(A) -%GETJFRAME get channels of an image. -% USAGE: -% [R,G,B] = getChannel( imread('picture.jpg') ); -% there is a more convenient way to display - % >> I = imread('s1.png'); imshow(I) - % >> J = [I(:,:)]; imshow(J) - -error(nargchk(1,1,nargin)); - -% for size -% size(A)可以得到矩阵A的大小 -% length(size(A))可以得到矩阵A的维数 - -s = size(A); - -if ( length(s) ~= 3 ) - error('The dimensions of Array must be 3.') -end -channels = s(end); - -for c = 1 : channels - varargout{c} = A(:,:,c); -end \ No newline at end of file diff --git a/my_img_util/im2gray.m b/my_img_util/im2gray.m deleted file mode 100644 index 7e93698..0000000 --- a/my_img_util/im2gray.m +++ /dev/null @@ -1,12 +0,0 @@ -function Gray = im2gray(Raw) -% 添加各种基本的灰度化处理方式,取RGB最大值等 - -if isstr(Raw) - Raw = imread(Raw); -end - -if size(Raw, 3) == 3 %~ismatrix(Raw) 旧版本不支持ismatrix - Raw = rgb2gray(Raw); -end - -Gray = Raw; \ No newline at end of file diff --git a/my_img_util/imdump.m b/my_img_util/imdump.m index 0c537f3..04769fa 100644 --- a/my_img_util/imdump.m +++ b/my_img_util/imdump.m @@ -18,48 +18,57 @@ function imdump(level, varargin) return; % Default: on dump end + debug = level > 1; + if ~isempty(dumpPath) dumpPath = [dumpPath '/']; end for i = 2:nargin param = varargin{i-1}; - filename = inputname(i); - if level <= 1 %(no debug info) - debuginfo = ''; - else - % carry with some debug info + + if debug % carry with some debug info % st(1): imdump st(2): function which called imdump st = dbstack; if length(st) > 1, n = 2; else n = 1; end funcname = st(n).name; line = st(n).line; - debuginfo = [' @', funcname, '-', num2str(line)]; + debuginfo = [inputname(i), ' @', funcname, '-', num2str(line)]; end if 1 == length(param) && ishandle(param) %% handle handle = param; figure(handle); % switch to that figure. - - if isempty(filename), filename = handle.Name; end - if isempty(filename), filename = handle.Number; end - + + if ~debug + filename = handle.Name; + if isempty(filename), filename = handle.Number; end + else + filename = debuginfo; + end + if saveEps - print([dumpPath, filename debuginfo, '.eps'],'-depsc'); + print([dumpPath, filename, '.eps'],'-depsc'); else - print(handle, '-djpeg', [dumpPath filename debuginfo]); + print(handle, '-djpeg', [dumpPath filename]); end else %% image image = param; + + if ~debug + filename = inputname(i); + else + filename = debuginfo; + end if saveEps h = figure; imshow(image); - print([dumpPath, filename debuginfo, '.eps'],'-depsc'); + print([dumpPath, filename, '.eps'],'-depsc'); close(h); else - imwrite(image, [dumpPath filename debuginfo, '.jpg']); + imwrite(image, [dumpPath filename, '.jpg']); end end end diff --git a/my_img_util/imshowblob.m b/my_img_util/imshowblob.m deleted file mode 100644 index f162d84..0000000 --- a/my_img_util/imshowblob.m +++ /dev/null @@ -1 +0,0 @@ -function J = imshowblob(IMAGE) \ No newline at end of file diff --git a/my_img_util/imshowcolor.m b/my_img_util/imshowcolor.m deleted file mode 100644 index 8ae34b2..0000000 --- a/my_img_util/imshowcolor.m +++ /dev/null @@ -1,74 +0,0 @@ -function imshowcolor(RGB, colorspace) -%IMSHOWCOLOR show the color channels of an image. -% IMSHOWCOLOR(RGB, colorspace) shows the specific colorspace when it is given, -% otherwise it shows all available channels. -% colorspace can be 'rgb, gray, hsv, ycbcr, ntsc, lab(not case sensitive)'. -% -% USAGE: -% IMSHOWCOLOR('dataset\roma\LRAlargeur26032003\IMG00579.jpg'); -% IMSHOWCOLOR('dataset\roma\BDXD54\IMG00002.jpg', 'hsv'); -% IMSHOWCOLOR('pictures/2.jpg', 'gray'); -% IMSHOWCOLOR('pictures/2.jpg', 'RGB'); -% IMSHOWCOLOR('pictures/2.jpg', 'YCbCr'); -% IMSHOWCOLOR('pictures/2.jpg', 'Lab'); -% foreach_file_do('pictures\shadowS', @IMSHOWCOLOR); -% foreach_file_do('pictures\shadowS', @IMSHOWCOLOR, 'hsv'); -% foreach_file_do('dataset\roma\LRAlargeur26032003\*.jpg', @IMSHOWCOLOR, 'hsv'); -% foreach_file_do('dataset\roma\LRAlargeur14062002\*.jpg', @IMSHOWCOLOR, 'hsv'); -% foreach_file_do('dataset\*.jpg', @IMSHOWCOLOR, 'hsv'); - -% TEST IMAGE: -% dataset\roma\LRAlargeur26032003\IMG00579.jpg -% 结论: 通过饱和度划分最可靠 -% 之后就是采用横轴统计进行区域选择,消失点,地平线的检测 -% TODO:getChannel改为子函数,支持更多颜色空间 -% help rgb2[tab] - -if isstr(RGB) - RGB = imread(RGB); -end - -if nargin < 2 % no specifies the colorspace - - [RGB_R, RGB_G, RGB_B ] = getChannel(RGB); - [HSV_H, HSV_S, HSV_V ] = getChannel(rgb2hsv(RGB)); - [YCbCr_Y, YCbCr_Cb, YCbCr_Cr] = getChannel(rgb2ycbcr(RGB)); - [YIQ_Y, YIQ_I, YIQ_Q ] = getChannel(rgb2ntsc(RGB)); - [LAB_L, LAB_A, LAB_B ] = getChannel(applycform(RGB,makecform('srgb2lab'))); - - figure; - implot( RGB, ... - RGB_R, RGB_G, RGB_B , ... - HSV_H, HSV_S, HSV_V , ... - YCbCr_Y, YCbCr_Cb, YCbCr_Cr , ... - YIQ_Y, YIQ_I, YIQ_Q , ... - LAB_L, LAB_A, LAB_B ... - ); - return; -end - -% 通过eval将字符串作为matlab命令执行 -if ~ isstr(colorspace) - error('colorspace must be a string.'); -end - -switch lower(colorspace) -case 'rgb' - I = RGB; -case 'lab' - I = applycform(RGB,makecform('srgb2lab')); -otherwise - convertFunc = ['rgb2' colorspace]; - if exist(convertFunc) == 2 - I = eval([convertFunc '(RGB)']); - else - error('invalid colorspace!'); % gray - end -end - -J = [I(:,:)]; - -% figure; -% imshow(RGB); -figure; -imshow(J); \ No newline at end of file diff --git a/my_img_util/imshowedge.m b/my_img_util/imshowedge.m deleted file mode 100644 index 32b8007..0000000 --- a/my_img_util/imshowedge.m +++ /dev/null @@ -1,77 +0,0 @@ -function imshowedge(Raw, method) -%IMSHOWEDGE extract the edge feature of a image. -% USAGE: -% normal case -% IMSHOWEDGE('pictures/lanemarking/light_sbs_vertical_www.jpg'); -% foreach_file_do('pictures/lanemarking/*light*.picture', @IMSHOWEDGE, 'canny'); -% effect of shadow -% IMSHOWEDGE('pictures/lanemarking/shadow/IMG00576.jpg', 'canny'); -% IMSHOWEDGE('pictures/lanemarking/shadow/IMG00576.jpg'); - -Raw = im2gray(Raw); - -if nargin < 2 % no specifies the method - Sobel = edge(Raw, 'sobel', 0.05); - Roberts = edge(Raw, 'roberts', 0.05); - Prewitt = edge(Raw, 'prewitt', 0.05); - LoG = edge(Raw, 'log', 0.003, 2.25); - Canny = edge(Raw, 'canny', [0.04 0.10], 1.5); - h = fspecial('gaussian',5); %高斯滤波 - Zerocross = edge(Raw,'zerocross',[ ],h); %zerocross图像边缘提取 - - figure; - implot(Raw, Sobel, Roberts, Prewitt, LoG, Canny, Zerocross); -else - Edge = edge(Raw, lower(method)); - figure; - implot(Raw, Edge); -end - -% % 默认参数下,Sobel效果最好 -% % 还可以返回阈值T -% T = []; -% dir = 'both'; -% Sobel = edge(Raw, 'sobel', T, dir); -% Roberts = edge(Raw, 'roberts', T, dir); -% Prewitt = edge(Raw, 'prewitt'); -% % default T and sigma -% LoG = edge(Raw, 'log'); -% Canny = edge(Raw, 'canny'); -% TODO: -% 45°边缘的Sobel -% zerocross -% 绘制参数渐变的效果图 调整参数? -% 调节某个参数 - -% 参考 数字图像处理的Matlab实现 - -% % matlab 边缘提取 -% close all -% clear all -% Raw=imread('tig.jpg'); %读取图像 -% Raw1=im2double(Raw); %将彩图序列变成双精度 -% Raw2=rgb2gray(Raw1); %将彩色图变成灰色图 -% [thr, sorh, keepapp]=ddencmp('den','wv',Raw2); -% Raw3=wdencmp('gbl',Raw2,'sym4',2,thr,sorh,keepapp); %小波除噪 -% Raw4=medfilt2(Raw3,[9 9]); %中值滤波 -% Raw5=imresize(Raw4,0.2,'bicubic'); %图像大小 -% BW1=edge(Raw5,'sobel'); %sobel图像边缘提取 -% BW2=edge(Raw5,'roberts'); %roberts图像边缘提取 -% BW3=edge(Raw5,'prewitt'); %prewitt图像边缘提取 -% BW4=edge(Raw5,'log'); %log图像边缘提取 -% BW5=edge(Raw5,'canny'); %canny图像边缘提取 -% h=fspecial('gaussian',5); %高斯滤波 -% BW6=edge(Raw5,'zerocross',[ ],h); %zerocross图像边缘提取 -% figure; -% subplot(1,3,1); %图划分为一行三幅图,第一幅图 -% imshow(Raw2); %绘图 -% figure; -% subplot(1,3,1); -% imshow(BW1); -% title('Sobel算子'); -% subplot(1,3,2); -% imshow(BW2); -% title('Roberts算子'); -% subplot(1,3,3); -% imshow(BW3); -% title('Prewitt算子'); diff --git a/my_img_util/imshowforegrond.m b/my_img_util/imshowforegrond.m deleted file mode 100644 index e1cd437..0000000 --- a/my_img_util/imshowforegrond.m +++ /dev/null @@ -1,18 +0,0 @@ -function J = imshowforeground(IMAGE, METHOD) - - - -switch upper(feature) -case 'light' - % threshold = 200;%200; - % I(I < threshold) = 0;he - % I(I >= threshold) = 1; - % Binary = logical(I); - threshold = graythresh(I); - Binary = im2bw(I, threshold); - Binary = bwareaopen(Binary, 300 ); - -case 'histeq' - I = histeq(I); - % threshold = graythresh(I); - Binary = im2bw(I, 243/255); \ No newline at end of file diff --git a/my_img_util/imshowhough.m b/my_img_util/imshowhough.m deleted file mode 100644 index 3b0357e..0000000 --- a/my_img_util/imshowhough.m +++ /dev/null @@ -1,35 +0,0 @@ -function imshowhough(Raw) -%IMSHOWHOUGH extract the hough lines of an image. -% USAGE: -% normal case -% IMSHOWHOUGH('pictures/lanemarking/light_singlelane.jpg'); -% effect of shadow -% IMSHOWHOUGH('pictures/lanemarking/shadow/IMG00576.jpg'); - -Raw = im2gray(Raw); -BW = edge(Raw, 'canny'); - -[H,T,R] = hough(BW); % [H,theta,rho] -P = houghpeaks(H,2); -imshow(H,[],'XData',T,'YData',R,'InitialMagnification','fit'); -xlabel('\theta'), ylabel('\rho'); -axis on, axis normal, hold on; -plot(T(P(:,2)),R(P(:,1)),'s','color','white'); - -% Finding the Hough peaks (number of peaks is set to 10) -% P = houghpeaks(H,2,'threshold',ceil(0.2*max(H(:)))); - -% x = T(P(:,2)); -% y = R(P(:,1)); - -%Fill the gaps of Edges and set the Minimum length of a line -lines = houghlines(BW,T,R,P,'FillGap',170,'MinLength',50); - -figure; -HoughLine = Raw; -implot(Raw, BW, HoughLine); -for i = 1:length(lines) - xy = [lines(i).point1; lines(i).point2]; - hold on; - plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','red'); -end \ No newline at end of file diff --git a/my_img_util/imshowlight.m b/my_img_util/imshowlight.m deleted file mode 100644 index c07b298..0000000 --- a/my_img_util/imshowlight.m +++ /dev/null @@ -1,73 +0,0 @@ -function imshowlight(Raw, method) -%IMSHOWLIGHT extract the light feature of a image. -% USAGE: -% normal case -% IMSHOWLIGHT('pictures/lanemarking/light_sbs_vertical_www.jpg'); -% IMSHOWLIGHT('pictures/lanemarking/light_highway_sbs.jpg'); -% IMSHOWLIGHT('pictures/lanemarking/light_highway_sbs.jpg', 'entropythresh'); -% foreach_file_do('pictures/lanemarking/*light*.picture', @IMSHOWLIGHT, 'graythresh'); -% effect of shadow -% IMSHOWLIGHT('pictures/lanemarking/shadow/IMG00576.jpg', 'threshthresh'); -% IMSHOWLIGHT('pictures/lanemarking/shadow/IMG00576.jpg'); -% fixedthresh entropythresh - -% _light_* stronglight - -Raw = im2gray(Raw); - -if nargin < 2 - Otsu = im2bw(Raw, graythresh(Raw)); - Iterative = im2bw(Raw, threshthresh(Raw)); - MaxEntropy = im2bw(Raw, entropythresh(Raw)); - % 直方图均衡化后效果更不好 - Histeq = histeq(Raw); AfterHisteq = im2bw(Raw, 240/255); - figure; - implot(Raw, Otsu, Iterative, MaxEntropy, AfterHisteq); -else - BW = im2bw(Raw, eval([method '(Raw)'])); - figure; - imshow(BW); -end - -function thres = fixedthresh(I) -thres = 240/255; - -function thres = threshthresh(I) -% 迭代法 -thres = 0.5 * ( double(min(I(:))) + double(max(I(:))) ); -done = false; -while ~done - g = I >= thres; - Tnext = 0.5 * (mean(I(g))+ mean(I(~g))); - done = abs(thres - Tnext) < 0.5; - thres = Tnext; -end -thres = thres/255; - -function thres = entropythresh(I) -%一维最大熵法 http://www.ilovematlab.cn/thread-84584-1-1.html -h = imhist(I); -h1 = h; -len=length(h); %求出所有的可能灰度 -[m,n]=size(I); %求出图像的大小 -h1=(h1+eps)/(m*n); %算出各灰度点出现的概率 -for i=1:(len-1) - if h(i)~=0 - P1=sum(h1(1:i)); - P2=sum(h1((i+1):len)); - else continue; - end - H1(i)=-(sum(P1.*log(P1))); - H2(i)=-(sum(P2.*log(P2))); - H(i)=H1(i)+H2(i); -end -m1 = max(H); -thres = find(H == m1); -thres = thres/255; - -% 二值化的方法: -% 全局阈值:固定阈值,最佳阈值:迭代法,Otsu最大类间方差法 -% 局部阈值: -% Matlab实现一书源代码中的各种方法 -% 直方图统计特征 -% 最大熵法保留最大信息量,不适合 \ No newline at end of file diff --git a/my_img_util/imshowsky.m b/my_img_util/imshowsky.m deleted file mode 100644 index 6f5ce12..0000000 --- a/my_img_util/imshowsky.m +++ /dev/null @@ -1,441 +0,0 @@ -function SKY = imshowsky(RGB) -% RGB = 'dataset\roma\BDXD54\IMG00002.jpg'; -% RGB = 'dataset\roma\LRAlargeur26032003\IMG00579.jpg'; -% RGB = 'dataset\IMG03326.jpg'; % 干净的例子,论文中用 -% RGB = 'dataset\IMG00002_ll_s_paper.jpg'; %这个也行!!论文中用 -% RGB = 'dataset\IMG02210_s_paper.jpg'; -% RGB = 'dataset\IMG00164_paper.jpg'; -% RGB = 'dataset\IMG00030_s_paper.jpg'; -%IMSHOWCOLOR show the color channels of an image. -% USAGE: -% TEST IMAGE: -% 之后就是采用横轴统计进行区域选择,消失点,地平线的检测 -% TODO:getChannel改为子函数,支持更多颜色空间 -% help rgb2[tab] -% ---------------------------- -% s - shadowy 有物体的投影 -% ss - more shadowy -% S - 大面积投影 -% n - noise 其他噪声 -% l - lu 有高亮的区域 -% ll - 光照严重不均衡 -% c - clean - -% IMG00164_paper -% ---------------------------- - -% 新想法: 阴影的颜色值是物体颜色值在某个空间的shift,考察这个shift可以还原 -close all; -if isstr(RGB) - RGB = imread(RGB); -end - -height = 150; -width = 200; -% RGB = imresize(RGB, [300, 400]); -RGB = imresize(RGB, [height, width]); - -[RGB_R, RGB_G, RGB_B ] = getChannel(RGB); - -% 调整对比度,防止整体偏亮或者偏暗的情形 -% % 对各通道进行直方图均衡化(基于统计信息,处理后图像不自然平滑,产生大量噪点) -% RGB_R = histeq(RGB_R); -% RGB_G = histeq(RGB_G); -% RGB_B = histeq(RGB_B); -% RGB = cat(3, RGB_R, RGB_G, RGB_B); - -[HSV_H, HSV_S, HSV_V ] = getChannel(rgb2hsv(RGB)); - -% 饱和度计算(对比HSV_S看不出区别) -% 最大值为0时,000全黑的点饱和度为0 -% RGB_MAX = RGB_MIN 时, 饱和度为0 -RGB_MIN = min(min(RGB_R, RGB_G) , RGB_B); -RGB_MAX = max(max(RGB_R, RGB_G) , RGB_B); -RGB_MAX_NO_ZERO = RGB_MAX; -RGB_MAX_NO_ZERO(RGB_MAX_NO_ZERO == 0) = 1; -Saturate = double(RGB_MAX - RGB_MIN) ./ double(RGB_MAX_NO_ZERO) ; - -% 发现阴影的B分量偏高 这里的阴影是高光造成的深影,饱和度高 -Shadowness = double(RGB_B - RGB_MIN) ./ double(RGB_MAX + 1); % Shadow = (RGB_MAX == RGB_B) & (RGB_MAX < 80); % 较准确 -Treeness = double(abs(RGB_MAX - RGB_B)) ./ double(RGB_MAX + 1); - -Tree = Treeness > 0.3; % 0.2 % 用histeq和graythresh效果不好 -Tree = imclose(Tree, strel('square',3));% Tree = imdilate(Tree, strel('square',3));imclose imopen -Tree = bwareaopen(Tree, 50); % 车道线也去除掉 -% Tree = imdilate(Tree, strel('square',3)); -% 注意图像的点可能会因为显示大小问题而不显示 图像不赋初值,大小可能出错 -Boundary = zeros(size(Tree)); -Boundary_True = zeros(size(Tree)); -mid = size(Tree, 2)/2; -last_r = size(Tree, 1); -left = 1; -for c = 1 : size(Tree, 2) - for r = size(Tree, 1) : -1 : 1 - if 1 == Tree(r, c) - Boundary(r, c) = 1; - break; - end - end -end - -for r = size(Tree, 1) : -1 : 1 - for c = mid : size(Tree, 2) - if 1 == Tree(r, c) - Boundary_True(r, c) = 1; - break; - end - end - for c = mid : -1 : 1 - if 1 == Tree(r, c) - Boundary_True(r, c) = 1; - break; - end - end -end -Boundary_True = Boundary_True & Boundary; -% 从中间向两边找效果不好 -% 任务: 画出路面区域 -% 换种方法直线拟合 标注出区域 -Lines = RGB; -figure; implot(RGB, Treeness, Tree, Boundary, Boundary_True, Lines); -% 先画点 -hold on -for c = 1 : size(Tree, 2) - for r = size(Tree, 1) : -1 : 1 - if 1 == Boundary_True(r, c) - plot(c, r, '+'); - break; - end - end -end - -% 区分左右车道线 -% 可能没找到 -% BoudaryLine_left = detectline(Boundary_True, [-80:0]); -% BoudaryLine_right = detectline(Boundary_True, [0:80]); -lines = detectline(Boundary_True, [-89:89]); % 防止漏检测 -if length(lines) < 1 - error('no line found!'); -end - -if length(lines) == 2 - BoudaryLine_left = lines(1); - BoudaryLine_right = lines(2); -else - BoudaryLine_left = lines(1); - plotline(BoudaryLine_left.point1, BoudaryLine_left.point2,'LineWidth',5,'Color','red'); - return; -end - -if isempty(BoudaryLine_left) && isempty(BoudaryLine_right) - error('no line found!'); -end - -if isempty(BoudaryLine_left) - plotline(BoudaryLine_right.point1, BoudaryLine_right.point2,'LineWidth',5,'Color','red'); - return; -end - -if isempty(BoudaryLine_right) - plotline(BoudaryLine_left.point1, BoudaryLine_left.point2,'LineWidth',5,'Color','red'); - return; -end - -% 两个直线可能相同,相同后交点就求不出来了 -theta1 = lines(1).theta; -theta2 = lines(2).theta; - -% 画消失点 圆圈o -vanishPoint = linemeetpoint( BoudaryLine_left.point1,BoudaryLine_left.point2,BoudaryLine_right(1).point1, BoudaryLine_right.point2 ); - -% plot -hold on; -plot(vanishPoint(1), vanishPoint(2), 'ro'); -% 水平线horison 把消失点所在的水平位置设为地平线 -plotline([1, vanishPoint(2)], [size(Tree, 2), vanishPoint(2)], 'LineWidth',1,'Color','blue'); -endPoint1 = linemeetpoint( BoudaryLine_left.point1, BoudaryLine_left.point2, [1, size(Tree, 1)], [4, size(Tree, 1)]); % 注意坐标反的 试试plot(1, 5, 'b*'); -endPoint2 = linemeetpoint( BoudaryLine_right.point1, BoudaryLine_right.point2, [1, size(Tree, 1)], [4, size(Tree, 1)]); -plot(endPoint1(1), endPoint1(2), 'r*'); -plot(endPoint2(1), endPoint2(2), 'r*'); - -plotline(vanishPoint, endPoint1,'LineWidth',1,'Color','yellow'); -plotline(vanishPoint, endPoint2,'LineWidth',1,'Color','yellow'); - -% 第二步,车道线特征提取 -% ROI设置 截取地平线以下的部分 简单地取地平线以下的部分 -horison = floor(vanishPoint(2)); % 有可能horison为负数 特殊图片 -ROI = RGB(horison:end,:,:); - -% 根据 -% 只检测路面区域内的 计算左右点 -% RGB_MEAN 不包含RGB_B RGB_MIN MEAN 效果很差 - -V_ROI = double(HSV_V(horison:end,:));% V_ROI = HSV_V(horison:end,:); 注意修改了 -S_ROI = HSV_S(horison:end,:); -[h, w] = size(V_ROI); - -DLD = zeros(h, w); -DLD_improved = zeros(h, w); - -end1 = min(endPoint2(1), endPoint1(1)); -end2 = max(endPoint2(1), endPoint1(1)); - -% 进一步地,仅在路面区域内进行求解 -for r = 1 : h % size(Tree, 1) : -1 : (horison-1) - mw = ceil(5 * r / h);% marking width - - left = ceil( vanishPoint(1) - (vanishPoint(1) - end1)* r / h); - right = ceil( vanishPoint(1) + (end2 - vanishPoint(1))* r / h); - left = max(1, left); - right = min(right, w); - - for c = (mw+left) : (right - mw ) - % 直接采用该公式的效果不好,改成添加饱和度 可以过滤掉阴影 - % DLD_improved = - % DLD 是大于左边一定范围且大于右边一定范围 - % DLD(r, c) = 2* V_ROI(r, c) - (V_ROI(r , c - mw)+V_ROI(r , c + mw)) - abs(V_ROI(r , c - mw) - V_ROI(r , c + mw)); - - DLD(r, c) = (V_ROI(r, c) - max(V_ROI(r , c - mw), V_ROI(r , c + mw))) ./ (V_ROI(r , c - mw)+V_ROI(r , c + mw)) ; - % DLD(r, c) = (1-S_ROI(r, c))*V_ROI(r, c) ./ (V_ROI(r , c - mw)+V_ROI(r , c + mw)); - DLD_improved(r, c) = V_ROI(r, c) ./ (V_ROI(r , c - mw)+V_ROI(r , c + mw)); - % 考虑对称性反而不好,考虑饱和度也不好,题目变化? - % DLD_S(r, c) = 2* S_ROI(r, c) - (S_ROI(r , c - mw)+S_ROI(r , c + mw)) - abs(S_ROI(r , c - mw) - S_ROI(r , c + mw)); - % k = min(V_ROI(r , c - mw), V_ROI(r , c + mw)) ./ max(V_ROI(r , c - mw), V_ROI(r , c + mw)); - % DLD_improved(r, c) = k * DLD(r, c); - % - 2*S_ROI(r, c); - end -end - -% 迭代的意义不大 -% DLD1 = filterDLD(HSV_V(horison:end,:)); -% DLD2 = filterDLD(DLD1); - -% 归一化 -DLD = mat2gray(DLD); -DLD_improved = mat2gray(DLD_improved); -Marking = (DLD_improved>0.48); % 0.7 -% Marking = imclose(Marking, strel('square',3)); % imopen -Marking = bwareaopen(Marking, 35); -% 改进 取中点 -% ------------------------------------ - -% 检测直线的范围确定 -lines = detectline(Marking, [ceil(min(theta1, theta2)):floor(max(theta1, theta2))]); % 防止漏检测 - -MarkingLine = lines(1); - -% close all; -imwrite(ROI, 'results/ROI.jpg'); -imwrite(DLD_improved, 'results/DLD.jpg'); - - -RGB_Marked = RGB; - -% horizon!!! 拼写错误 -% for c = 1 : width - % for r = horison : height - % if 1 == Marking(r +1 -horison, c) - % RGB_Marked(r, c, 1) = 0; - % RGB_Marked(r, c, 2) = 255; - % RGB_Marked(r, c, 3) = 0; - % end - % end -% end -figure;imshow(RGB_Marked); - -startPoint3 = linemeetpoint( MarkingLine.point1, MarkingLine.point2, [1, 0], [4, 0]); - -endPoint3 = linemeetpoint( MarkingLine.point1, MarkingLine.point2, [1, size(Tree, 1)], [4, size(Tree, 1)]); % 注意坐标反的 试试plot(1, 5, 'b*'); -endPoint3(2) = endPoint3(2) + horison; -startPoint3(2) = startPoint3(2) + horison; - -% plotline(vanishPoint, endPoint3,'LineWidth',3,'Color','green'); -plotline(startPoint3, endPoint3,'LineWidth',3,'Color','red'); - - - -% figure; implot(RGB, HSV_S, DLD, DLD_improved, Marking, Marking2, RGB); -hold on; - -% 复制自上文绘图 -hold on; -plot(vanishPoint(1), vanishPoint(2), 'ro'); -% 水平线horison 把消失点所在的水平位置设为地平线 -plotline([1, vanishPoint(2)], [size(Tree, 2), vanishPoint(2)], 'LineWidth',3,'Color','blue'); -endPoint1 = linemeetpoint( BoudaryLine_left.point1, BoudaryLine_left.point2, [1, size(Tree, 1)], [4, size(Tree, 1)]); % 注意坐标反的 试试plot(1, 5, 'b*'); -endPoint2 = linemeetpoint( BoudaryLine_right.point1, BoudaryLine_right.point2, [1, size(Tree, 1)], [4, size(Tree, 1)]); -plot(endPoint1(1), endPoint1(2), 'r*'); -plot(endPoint2(1), endPoint2(2), 'r*'); - -plotline(vanishPoint, endPoint1,'LineWidth',3,'Color','yellow'); -plotline(vanishPoint, endPoint2,'LineWidth',3,'Color','yellow'); - - -% 添加显示区域 - - - -% 固定宽度的DLD 采用模板也行吧 -% - HSV_V 作为改进 颜色信息利用上了 -% template_DLD = ones(1, 2*mw); -% template_DLD(1:ceil(mw/2)) = -1; -% template_DLD(ceil(mw*3/2):mw*2) = -1; - -% DLD_V = imfilter(HSV_V(horison:end,:), template_DLD, 'corr', 'replicate'); -% DLD_S = imfilter(HSV_S(horison:end,:), -template_DLD, 'corr', 'replicate'); - -%figure;imshow(DLD); -% Markingness = HSV_V .* (1 - HSV_S) ; -% Marking = Markingness > 0.8; -% (HSV_H + 0.5 < HSV_V) & (HSV_S + 0.5 < HSV_V); - -function DLD = filterDLD(GRAY) -% 类似元胞自动机的更新思想 -[h, w] = size(GRAY); -DLD = zeros(h, w); -for r = 1 : h % size(Tree, 1) : -1 : (horison-1) - mw = ceil(5 * r / h);% marking width - % int16( 10 * (r - horison) / (height - horison) ); - for c = (mw+1) : w - mw - % 直接采用该公式的效果不好,改成添加饱和度 可以过滤掉阴影 - % DLD_improved = - DLD(r, c) = 2* GRAY(r, c) - (GRAY(r , c - mw)+GRAY(r , c + mw)) - abs(GRAY(r , c - mw) - GRAY(r , c + mw)); - end -end - -return; - -% vanishPoint - -% 车道标记检测的新方法 -% DLD方法 - -% 三角形区域 -% 车道标记? 对HSV_V 进行histeq -% HSV_V = histeq(HSV_V); -% 亮度足够大 HSV_S 足够小 -% HSV_S = 0 尽量不要和V有关,否则受光照影响大 -% 亮度相对高,饱和度相对低,融合DLD -% 亮度减去左侧亮度 -% 消失点的高度 - -Filtered = medfilt2(Saturate2); -% Filtered = filter2(fspecial('average',5), Filtered); -Tree = im2bw(Filtered, 0.3); -Tree = imfill(Tree, 'holes'); -Tree = bwareaopen(Tree, 100); - -% Saturate_adjust = Saturate - Shadowness*0.7; - - - -implot(RGB, Shadowness, Saturate, Tree1, Treeness); -return; - -% 也可以简单地取近似 Saturate = double(RGB_MAX - RGB_MIN) ./ double(RGB_MAX + 1) ; -% saturate 的问题在于 阴影的饱和度很大,会干扰 -RG_MAX = max(RGB_R, RGB_G); -RG_MIN = min(RGB_R, RGB_B); - -Saturate3 = double(RG_MAX - RG_MIN) ./ double(RG_MAX + 1) ; -% 研究要有方法,不能瞎猜,最好是分析数据,发现规律,做了图像标记后,观察数据!以后的工作就是这个! -% 阴影的B分量明显偏大 -%RG_MAX比RGB_G更显著 double(RGB_G - RGB_B) ./ double(RGB_G + 1) ; -%分子再次加强 -Saturate2 = double(RG_MAX - RGB_B) ./ double(RG_MAX + 1) ; -%Saturate3 = 2*Saturate2 + Saturate ; - -% 一半的马路存在阴影的情形下 或者是墙壁,没有绿色 -% 在大面积阴影内部找边缘修补 对边缘图进行修复 -% 注意不能用最大类间方差graythresh(Saturate2)取最优阈值 而是均衡化后固定阈值 也不建议均衡化 -% 根据最大值调整阈值max(Saturate2(:)) 基本都是0.99** -% 去掉孤立的噪点 直接先进行中值滤波就没有噪点了 - -% 二值图像去噪bwareaopen 去除小面积的 稍微膨胀下(但引入噪声) -% f=bwareaopen(h,50); -% figure,imshow(f) -% g=imdilate(f,strel('disk',2));figure,imshow(g) -% - -% Shadow = RGB_MAX < 80; 效果不好 -% Shadow = Saturate - Saturate2; -% Shadow = im2bw(Shadow, 0.6); -% Shadow = bwareaopen(Shadow, 100); -% Shadow = double(RGB_B - RG_MAX) ./ double(RGB_B + 1); - -% bw1 = imfill(bw, 'holes'); 填充二值图中的洞 -% 注意图片是非负的类型 取-则为取反运算 - -% Edge = edge(Shadow, 'sobel'); % 创新点,将阴影区域和非阴影区域独立找特征点,之后结合 -% Edge = Edge & Shadow; - -% 提取特征点 - -figure; % HSV_V,Saturate3, -implot(RGB, HSV_H, Saturate, Saturate2, Tree, Saturate3); -return; - -Filtered_Median = medfilt2(HSV_V); -TREENESS = abs(HSV_V - Filtered_Median); -TREENESS = histeq(TREENESS); - -TREE = im2bw(TREENESS) & (HSV_S > 0.7); -% MARKING = (HSV_V - HSV_S) ./ (double(RGB_MAX - RGB_MIN + 1)/255.0); -% MARKING = mat2gray(MARKING); -% MARKING = histeq(MARKING); - -figure; -implot(RGB, HSV_H, HSV_S, HSV_V, TREENESS, TREE); -% implot(RGB, HSV_H, HSV_S, HSV_V, abs(HSV_H - HSV_S) .* HSV_S); -% 去除饱和度大于树木的即可! -return; -% + T 添加阈值 - -% HSV_MIN = min(min(HSV_H, HSV_S) , HSV_V); -% HSV_MAX = max(max(HSV_H, HSV_S) , HSV_V); -% 尝试了将HSV分量线性运算的结果,效果不好,消除阴影的同时路面也不突出了 - -%ROAD = (HSV_V - HSV_S > 0.5); -% ROAD = histeq(HSV_MEAN); - -% implot(RGB, HSV_H, HSV_S, HSV_V, RGB_R, RGB_G, RGB_B); -% -implot(RGB, HSV_H, HSV_S, HSV_V, (RGB_MAX<30), (RGB_MAX<60), (RGB_MAX<90)); -% (RGB_MAX<60) 比较合适 -% SHADOW = - -return; - - -GREENNESS = (255 + max(double(RGB_G), double(RGB_R)) - double(RGB_B))/2; -% 偏绿偏黄 -TREENESS = (RGB_R + RGB_G - RGB_B); -% TREENESS = 255 * double(TREENESS + 255)/ double( 510 + 255); - -TREE = GREENNESS > 125; % HSV_S/ > 0.5; % 非常饱和 且明显偏绿 - -% 找到非阴影的彩色点,即饱和度足够大,但亮度不是黑色的 -% ROAD = HSV_V > 0.3; -SHADOW = (HSV_H > HSV_V) & (HSV_S > HSV_V) & (RGB_MAX < 30); - - -BLUENESS = (255 + double(RGB_B) - max(double(RGB_R), double(RGB_G)))/2 ; % RGB:0-255 HSV:0-1 - -BLUE = BLUENESS > 125; % 固定阈值 -SKYNESS = (HSV_V + 255 - HSV_S)/2; -SKY = (HSV_V > HSV_H + 0.2) & (HSV_H > HSV_S + 0.2) & (HSV_V - HSV_S > 0.6); % & BLUE 天不一定蓝,阴天 -SATURATELESS = (HSV_H > HSV_S) & (HSV_V > HSV_S); - -MARKING = (HSV_H + 0.5 < HSV_V) & (HSV_S + 0.5 < HSV_V); -% ROAD = (SATURATELESS | SHADOW > SKY); - - -% 局部阈值 - -%implot(RGB, TEST);return; -% 作为因子比较好,正比反比 -% imshow(RGB); -implot(RGB, BLUENESS, SKYNESS, SKY, SATURATELESS, SHADOW, MARKING,ROAD); - - - diff --git a/my_img_util/linemeetpoint.m b/my_img_util/linemeetpoint.m deleted file mode 100644 index ba843ec..0000000 --- a/my_img_util/linemeetpoint.m +++ /dev/null @@ -1,35 +0,0 @@ -function point = linemeetpoint( X1,Y1,X2,Y2 ) -%LINEMEETPOINT compute the intersection point of two straight lines represented by end points. -% LINEMEETPOINT is going to be removedd. Use LINEOBJ instead. -% -% line1: X1, Y1, line2: X2, Y2 -% See also LINEOBJ LINEOBJ/CROSS. - -% Ref: http://blog.sina.com.cn/s/blog_60b9b8890100t2b9.html -if X1(1)==Y1(1) - X=X1(1); - k2=(Y2(2)-X2(2))/(Y2(1)-X2(1)); - b2=X2(2)-k2*X2(1); - Y=k2*X+b2; -end -if X2(1)==Y2(1) - X=X2(1); - k1=(Y1(2)-X1(2))/(Y1(1)-X1(1)); - b1=X1(2)-k1*X1(1); - Y=k1*X+b1; -end -if X1(1)~=Y1(1)&X2(1)~=Y2(1) - k1=(Y1(2)-X1(2))/(Y1(1)-X1(1)); - k2=(Y2(2)-X2(2))/(Y2(1)-X2(1)); - b1=X1(2)-k1*X1(1); - b2=X2(2)-k2*X2(1); - if k1==k2 - X=[]; - Y=[]; - else - X=(b2-b1)/(k1-k2); - Y=k1*X+b1; - end -end - -point = [X Y]; \ No newline at end of file diff --git a/my_img_util/plotflow.m b/my_img_util/plotflow.m deleted file mode 100644 index cc31f79..0000000 --- a/my_img_util/plotflow.m +++ /dev/null @@ -1,34 +0,0 @@ -function plotFlow(u, v, rSize, scale) -%功能:绘制光流场 -%输出:u-横向光流矢量 scale-光流场规模 -%输出:v-纵向光流矢量 imgOriginal-光流场显示的图像 rSize-可见光流矢量区域的尺寸 -%输出:fz-参考像素点的灰度值沿z方向的偏导数 -% 修改自 http://www.ilovematlab.cn/thread-280248-1-1.html -% 原图不需要,仅仅plot光流 -% 添加两个方向的显示 -% set(gca,'YDir','reverse');似乎没什么用 - -nargneed = 4; - -if nargin < nargneed - scale = 3; - nargneed = nargneed - 1; - if nargin < nargneed - rSize = 5; - end -end - -% Enhance the quiver plot visually by showing one vector per region -for i = 1:size(u,1) %u的行数 u v 一样大小 - for j = 1:size(u,2) %u的列数 - if floor(i/rSize)~=i/rSize || floor(j/rSize)~=j/rSize %判断不等 5的倍数出有点 - u(i,j)=0; - v(i,j)=0; - end - end -end - -quiver(u, v, scale, 'color', 'r', 'linewidth', 2);%线宽是2,颜色是b,即蓝色,r是红色 -% set(gca,'YDir','reverse');%gca当前轴处理 -quiver(u, zeros(size(v)), scale, 'color', 'g', 'linewidth', 2);%线宽是2,颜色是b,即蓝色,r是红色 -quiver(zeros(size(u)), v, scale, 'color', 'b', 'linewidth', 2);%线宽是2,颜色是b,即蓝色,r是红色 \ No newline at end of file diff --git a/my_img_util/plotline.m b/my_img_util/plotline.m deleted file mode 100644 index e924078..0000000 --- a/my_img_util/plotline.m +++ /dev/null @@ -1,5 +0,0 @@ -function plotline(point1, point2, varargin) -xy = [point1; point2]; -hold on; -plot(xy(:,1),xy(:,2), varargin{:}); - diff --git a/my_img_util/plotobj.m b/my_img_util/plotobj.m deleted file mode 100644 index 6e9a428..0000000 --- a/my_img_util/plotobj.m +++ /dev/null @@ -1,44 +0,0 @@ -function h = plotobj(varargin) -%PLOTOBJ Plot objects which has plot method. -% PLOTOBJ(I,J,K,...) plots I,J,K,... with automatic color arrangement, -% each input can be an obj, or array of objs. -% variable name of each input will be marked. -% -% Example -% --------- -% Plot the images of given folder. -% -% l1 = LineObj([10 100], [20 60]); -% l2 = LineObj([20 150], [21 55]); -% l3 = LineObj([100 105], [25 112]); -% plotobj(l1,l2,l3); -% -% See also IMPLOT. - -% plot lines and add legend - -h = gcf; -c = jet(nargin); % color -name = cell(1,nargin); -handles = zeros(1,nargin); - -for i = 1:nargin - obj = varargin{i}; - name{i} = inputname(i); - if length(obj)> 1 - for ii = 1:length(obj) - tmp = obj(ii).plot('color', c(i,:)); % plotobj(obj); % recursive - end - handles(i) = tmp; - elseif isobject(obj) - handles(i) = obj.plot('color', c(i,:)); - else - error('unexpected inputs.'); - end -end - -global isAnnotate - -if isAnnotate - legend(handles, name{:}); %'Location', 'SouthEastOutside'% 如果生成论文的图片,则可以再关闭标注或覆盖标? -end \ No newline at end of file diff --git a/my_img_util/plotpoint.m b/my_img_util/plotpoint.m deleted file mode 100644 index 7f48f25..0000000 --- a/my_img_util/plotpoint.m +++ /dev/null @@ -1,34 +0,0 @@ -function h = plotpoint(varargin) -%PLOTOBJ plot points and add remarks. - -h = gcf; -c = jet(nargin); % color -name = cell(1,nargin); -handles = zeros(1,nargin); - -for i = 1:nargin - obj = varargin{i}; - name = inputname(i); - if length(obj) == 2 - % points - plot(obj(1), obj(2), 'yo', 'markersize', 10); -global isAnnotate - if isAnnotate - text(obj(1)+10, obj(2)-10, ['\color{black}', sprintf([name, '(%.2f, %.2f)'], obj(1), obj(2))]); - end - elseif length(size(obj)) == 2 % isbw(obj) Function ISBW has been removed. - % plot positive points of a binary image. - [nRow, nCol] = size(obj); - for r = 1:nRow - for c = 1 : nCol - if 1 == obj(r,c) - plot(c, r, 'b*'); % 'o' 'color', c(i,:) - % Notice the x -> c, y -> r - end - end - end - else - error('unexpected inputs.'); - end -end - diff --git a/my_img_util/recover3dlayout.m b/my_img_util/recover3dlayout.m deleted file mode 100644 index 53047c8..0000000 --- a/my_img_util/recover3dlayout.m +++ /dev/null @@ -1,37 +0,0 @@ -function recover3dlayout(file) -% filename = 'shadowy_road'; -% filename = 'weak_shadows'; -% filename = 'lakecomo2008'; -% filename = 'clean_road'; -% filename = 'shadowy'; - -[pathstr,name,ext] = fileparts(file); - -% if ext~= 'jpg' -% ext = '.jpg'; - -I = imread(file); -imwrite(I,[name '.ppm']); - -dos(['photoPopupIjcv data/ijcvClassifier ' file ' "" results']); - -w=vrview(['results/' name '.wrl']); - -ext = '.pgm'; - -Support = imread(['results/', name, '.000', ext]); -Vertical = imread(['results/',name, '.090', ext]); -Sky = imread(['results/',name, '.sky', ext]); - -implot(I, Support, Vertical, Sky); - - -% |Class|X|Y| -% Support 000 .g -% Vertical 090 .v -% Left 090 135 -% Center 090 090 -% Right 090 045 -% Sky .sky -% Porous -por -% Solid -sol \ No newline at end of file diff --git a/my_img_util/selplot.m b/my_img_util/selplot.m deleted file mode 100644 index 4758bcc..0000000 --- a/my_img_util/selplot.m +++ /dev/null @@ -1,40 +0,0 @@ -function h = selplot(name, fig) -%SELPLOT select a subplot for plot dots, lines or whatever. -% -% Example -% ------- -% -% -% Football = imread('football.jpg'); -% Cameraman = imread('cameraman.tif'); -% implot(Football, Cameraman); -% selplot('Football'); -% imshow('kids.tif'); - -if nargin < 2 - fig = gcf; -end - -nAxes = 0; - -for ii = length(fig.Children):-1:1 % 倒序排列的 - - h = fig.Children(ii); - if ~strcmp(h.Type, 'axes') - continue; - end - - nAxes = nAxes + 1; % find 1 axes - - if isnumeric(name) && nAxes == name - fig.CurrentAxes = h; % subplot(h); - break; - end - - % 名称有问题,不一定匹配,建议用序号 - if isstr(name) && strcmp(h.Title.String, name) %~isempty( findstr(fig.Children(1).Title.String, name) ) - subplot(h); % 切换到子图 - break; % 如果重名,则仅返回第一次找到的(返回数组?) - end - -end diff --git a/my_img_util/subplott.m b/my_img_util/subplott.m deleted file mode 100644 index 55c76dd..0000000 --- a/my_img_util/subplott.m +++ /dev/null @@ -1,31 +0,0 @@ -function [hA] = subplott(nr,nc) -%function to return a figure handle and axes handles for tight subplots -% -%Inputs: -% r: number of rows -% c: number of columns -% -%Outputs: -% hA: axes handles to subplots (styled order, i.e. rows first then columns) -% -%See Also: subplot imshow -% -% http://www.mathworks.com/matlabcentral/answers/28673-imshow-border-tight-for-subplot - %Error Checking: - assert(nargin==2,'2 inputs expected'); - assert(isscalar(nr)&&isscalar(nc)); - %Other Constants: - rspan = 1./nr; %row span normalized units - cspan = 1./nc; %not the tv channel - na = nr*nc; %num axes - %Engine - rlow = flipud(cumsum(rspan(ones(nr,1)))-rspan); %lower edge - clow = cumsum(cspan(ones(nc,1)))-cspan; - [rg cg] = meshgrid(1:nr,1:nc); %grids - hA = zeros(na,1); - figure; - for ii = 1:na - pos = [clow(cg(ii)) rlow(rg(ii)) cspan rspan]; %positions - hA(ii) = axes('units','norm','outerposition',pos,'position',pos); %build axes - end - end \ No newline at end of file diff --git a/my_vehicle_vision_util/VehicleVision.m b/my_vehicle_vision_util/VehicleVision.m deleted file mode 100644 index ccc41e0..0000000 --- a/my_vehicle_vision_util/VehicleVision.m +++ /dev/null @@ -1,83 +0,0 @@ - -classdef VehicleVision - - properties - filenames - tracking - end - - methods - function obj = VehicleVision(imList, varargin) - % imList - % a string specifying the list of images. - % - % USER CONFIGURABLE OPTIONS - % - % Possible param/value options are: - % Supported specifications: - % 'tacking' - true to enable tracking module. Note the images should - % have same size and be sorted by time when tracking is on. - % 'displayLevel' - determine how much information to be displayed. (default is 1) - % 0 : no display, only output result to file (release) - % 1 : errors - % 2 : + warnings - % 3 : + show main figure (debug, time consuming) - % 4 : + output intermediate results (when encountering bugs) - % 5 : + progression (progressbar) - % 6 : + information (disp more information) - p = inputParser; - addRequired(p,'imList',@isstr); - addOptional(p,'displayLevel', 1,@isnumeric); - addOptional(p,'tracking', false,@isnumeric); - addOptional(p,'learning', false,@isnumeric); - parse(p,imList,varargin{:}); - - data=textread(name,'%s','delimiter','\n','whitespace',''); - nelem = str2num(char(data(1)));% first line of the file specify the number of elements. - filenames=data(2:nelem+1); - - obj.tracking = p.Results.tracking; - obj.displayLevel = p.Results.displayLevel; - - - % initalize: accuracy is more important than speed. - [Sky, Support, Vertical] = analyse3dLayout(filenames(1)); - - %% boundary detection using a more sophisticated boudary feature map - - - end - - function processing(obj) - infor = null; - for n = 1:length(filenames) - - I = imread(filenames(n)); - - % init the parameters. - if obj.tracking - - else - - end - - % Boundary feature extraction - for i = 1 : 2 % two road region - f = vvGetFeature(RoadRegion(i), 'S2'); - f = imclose(); - end - - % Boundary points extraction - - if ~obj.tracking - infor = null; - end - end - end - - end% methods -end% classdef - - -% old pattern: output = function(input, method) -% new pattern: pipeline(S2FeatureExtractor, BoundMarker, LineFitter, ViewConverter) \ No newline at end of file diff --git a/my_vehicle_vision_util/im2birdview.m b/my_vehicle_vision_util/im2birdview.m deleted file mode 100644 index 939207a..0000000 --- a/my_vehicle_vision_util/im2birdview.m +++ /dev/null @@ -1,56 +0,0 @@ -function BirdView = Img2birdview(Img, VP) - - [nRows, nCols, nChannels] = size(Img); - - if nargin < 2 - % VP = [floor(nRows/2), floor(nCols/2)]; - - % 方案1 取中心点方式 - % movingPoints = [nCols/4, nRows*3/4; nCols*3/4, nRows*3/4; ... - % 1, nRows; nCols, nRows] ; - - % 方案2 通过用户交互选择 - % h = figure; - % Imgshow(Img); - % maxfig; - % [x, y] = ginput(4); % 鼠标选择4个点 需要按照顺序:左上,右上,左下,右下 - % movingPoints = [x'; y']'; - % close(h); - - - % 方案3 可自由调整的区域,同步更新显示 - Transformed = Img; - implot(Img, Transformed); - - selplot('Img'); - - % 上左, 上右, 下右, 下左 顺序! - movingPoints = [175,666; 825,646; 1099,1008; -598,1029]; - h = impoly(gca, movingPoints); - roi2birdview(movingPoints); - - setColor(h,'yellow'); - addNewPositionCallback(h,@(p) roi2birdview(p)); % title(mat2str(p,3)) - - end - - % 内部函数直接共享数据 - function roi2birdview(movingPoints) - % title(mat2str(movingPoints,3));return - - % 改为上左, 上右, 下右, 下左 顺序!原来是 上左 上右 下左 下右 - fixedPoints = [1, 1; nCols, 1;... - nCols, nRows; 1, nRows]; - % fixedPoints = [1, 1; 20, 1;... - % 1, 20; 20, 20] ; - - tform = fitgeotrans(movingPoints, fixedPoints, 'projective'); - BirdView = imwarp(Img, tform, 'OutputView', imref2d([nRows, nCols])); - subplot(1,2,2); %selplot('Transformed'); - imshow(BirdView); - end -end - -% 图像统一命名为Img或IM 命名为I和im不方便替换 容易覆盖imshow showImg等 -% impoly imploy - diff --git a/my_vehicle_vision_util/im2vanishingpoint.m b/my_vehicle_vision_util/im2vanishingpoint.m deleted file mode 100644 index 6abfbf6..0000000 --- a/my_vehicle_vision_util/im2vanishingpoint.m +++ /dev/null @@ -1,88 +0,0 @@ -function [pointVP, vx, vy] = im2vanishingpoint(im1, im2) -% im2vanishingpoint(imread('dataset\dataset4\sequence\04562.jpg'),imread('dataset\dataset4\sequence\04563.jpg')); -% im2vanishingpoint(imread('dataset\dataset4\sequence\04564.jpg'),imread('dataset\dataset4\sequence\04565.jpg')); - -% folder = 'D:\Users\zqying\Documents\Github\OpenVehicleVision\dataset\dataset4\sequence\'; -% % load the two frames -% ori1 = imread([folder '04562.jpg']); -% ori2 = imread([folder '04563.jpg']); -% resize 交给外部来做 - -% =============================================== % - -% set optical flow parameters (see Coarse2FineTwoFrames.m for the definition of the parameters) -alpha = 0.012; -ratio = 0.75; -minWidth = 20; -nOuterFPIterations = 7; -nInnerFPIterations = 1; -nSORIterations = 30; - -para = [alpha,ratio,minWidth,nOuterFPIterations,nInnerFPIterations,nSORIterations]; - -% this is the core part of calling the mexed dll file for computing optical flow -% it also returns the time that is needed for two-frame estimation -tic; -[vx,vy,warpI2] = Coarse2FineTwoFrames(im1,im2,para); -toc - -% figure, implot(im1, im2, warpI2), maxfig; - -% plotFlow(vx, vy, im1, 10); -% maxfig; - -implot(vx, vy); -pointVP = getVP(vx, vy); - -if showVP - figure;imshow(im1,[0 255]); hold on; - plot(pointVP(1), pointVP(2), 'yo', 'markersize', 10); - text(pointVP(1), pointVP(2)+2, ['\color{yellow}', sprintf('%.2f, %.2f',pointVP(1), pointVP(2))]); - maxfig; -end - -% 先按照0做阈值分割 -function pointVP = getVP(vx, vy) - -BW_vx = vx > 0; -BW_vy = vy > 0; - -% figure; implot(BW_vx, BW_vy); - -% 初始VP为图像中心 -VPx = size(vx,2)/2.0; -VPy = size(vx,1)/2.0; - -% 只考虑了图像中心区域 -for r = ceil(size(vx,1)/4) : ceil(size(vx,1)*3/4) - for c = ceil(size(vx,2)/4) : ceil(size(vx,2)*3/4) - if BW_vx(r,c-1) == 0 && BW_vx(r,c) == 1 - VPx = double(VPx + c)/2; - break; - end - end -end -for r = ceil(size(vx,1)/4) : ceil(size(vx,1)*3/4) - for c = ceil(size(vx,2)/4) : ceil(size(vx,2)*3/4) - if BW_vy(r-1,c) == 0 && BW_vy(r,c) == 1 - VPy = double(VPy + r)/2; - break; - end - end -end - -pointVP = [VPx, VPy]; - -% 注意vx为浮点数 -% 每行的绝对值最小值点做平均 -% 正负中间 左侧大于0,右侧小于0 - -% 由于是渐变的,可以改成启发式地找中间值,二分法 -% 下一行从上一行附近找值 - -% VPx = floor(VPx); -% VPy = floor(VPy); - -% 1. set(gca,'YDir','reverse');作用何在? -% 2. 消失点是图像中心- 画出中心点看有无变化 -% 3. x显示的图中横纵轴合成不正确 \ No newline at end of file diff --git a/my_vehicle_vision_util/vvColorFeature.m b/my_vehicle_vision_util/vvColorFeature.m deleted file mode 100644 index 31b6f9c..0000000 --- a/my_vehicle_vision_util/vvColorFeature.m +++ /dev/null @@ -1,63 +0,0 @@ -function FeatureMap = vvColorFeature(I, feature) -%VVCOLORFEATURE -% USAGE: -% I = imread('IMG00071_ll_s_paper_ISM2015.jpg'); VVCOLORFEATURE(I); -[nRow, nCol, nChannel] = size(I); - -if nChannel ~= 3 - error('Input image must have 3 color channels.'); -end - -[RGB_R, RGB_G, RGB_B] = getChannel(I); -RGB_min = min(min(RGB_R, RGB_G) , RGB_B); -RGB_max = max(max(RGB_R, RGB_G) , RGB_B); - -if nargin < 2 % display test when no feature is specified. - - S = double(RGB_max - RGB_min) ./ double(RGB_max + 1); - S2 = double(RGB_max - RGB_B) ./ double(RGB_max + 1); - - Redness = histeq(RGB_R - max(RGB_G, RGB_B)); - % Greeness = mat2gray( RGB_G - max(RGB_R, RGB_B) ); - Greeness = double(RGB_G) - double(max(RGB_R, RGB_B)); - Greeness = histeq(Greeness); - Blueness = histeq(RGB_B - max(RGB_R, RGB_G)); - - test = cat(3, RGB_R, RGB_G, 255 - RGB_B); - test1 = cat(3, 255-RGB_R, 255-RGB_G, 255-RGB_B); - test2 = cat(3, RGB_R, RGB_G, RGB_R); - test3 = cat(3, RGB_R, RGB_G, RGB_G); - - implot(I, S, S2, ... - Redness, Greeness, Blueness, ... - test, test1, test2, test3); - - return; -end - -switch feature -case 'S2' - FeatureMap = double(RGB_max - RGB_B) ./ double(RGB_max + 1); -end - -% negative number -> zero for unsigned class. -% >> A = [1 2 4; 5 6 9]; -% >> A - 6 - -% ans = - -% -5 -4 -2 -% -1 0 3 - -% >> whos A -% Name Size Bytes Class Attributes - -% A 2x3 48 double - -% >> B = uint8(A); -% >> B - 6 - -% ans = - -% 0 0 0 -% 0 0 3 \ No newline at end of file diff --git a/my_vehicle_vision_util/vvCreateMask.m b/my_vehicle_vision_util/vvCreateMask.m deleted file mode 100644 index dc497e4..0000000 --- a/my_vehicle_vision_util/vvCreateMask.m +++ /dev/null @@ -1,37 +0,0 @@ -function [BW,maskedRGBImage] = vvCreateMask(RGB) -%createMask Threshold RGB image using auto-generated code from colorThresholder app. -% [BW,MASKEDRGBIMAGE] = createMask(RGB) thresholds image RGB using -% auto-generated code from the colorThresholder App. The colorspace and -% minimum/maximum values for each channel of the colorspace were set in the -% App and result in a binary mask BW and a composite image maskedRGBImage, -% which shows the original RGB image values under the mask BW. - -% Auto-generated by colorThresholder app on 20-Sep-2015 -%------------------------------------------------------ - - -% Convert RGB image to chosen color space -I = rgb2hsv(RGB); - -% Define thresholds for channel 1 based on histogram settings -channel1Min = 0.828; -channel1Max = 0.469; - -% Define thresholds for channel 2 based on histogram settings -channel2Min = 0.335; -channel2Max = 1.000; - -% Define thresholds for channel 3 based on histogram settings -channel3Min = 0.000; -channel3Max = 1.000; - -% Create mask based on chosen histogram thresholds -BW = ( (I(:,:,1) >= channel1Min) | (I(:,:,1) <= channel1Max) ) & ... - (I(:,:,2) >= channel2Min ) & (I(:,:,2) <= channel2Max) & ... - (I(:,:,3) >= channel3Min ) & (I(:,:,3) <= channel3Max); - -% Initialize output masked image based on input image. -maskedRGBImage = RGB; - -% Set background pixels where BW is false to zero. -maskedRGBImage(repmat(~BW,[1 1 3])) = 0; diff --git a/my_vehicle_vision_util/vvDirectionFilter.m b/my_vehicle_vision_util/vvDirectionFilter.m deleted file mode 100644 index 5ea0a26..0000000 --- a/my_vehicle_vision_util/vvDirectionFilter.m +++ /dev/null @@ -1,92 +0,0 @@ -I = 'dataset\roma\BDXD54\IMG00002.jpg'; % IMG00002 IMG00071 - -% function Filtered = vvDirectionFilter(I, method, preprocess, varargin) -% -% method = 'steergauss' -% vvDirectionFilter('dataset\roma\BDXD54\IMG00030.jpg') -% Gabor任ڼӴҶ任GaborƵͬ߶ȡͬȡصGabor ˲ƵʺͷӾϵͳԳʶڿռ򣬶άGabor˲һ˹˺ƽ沨ij˻ģ -% ÿɵ˲ȥض -% sobelԵݶȷʱģõGx,Gy,ֵԼıԵatan(Gy/Gx) -% ɸѡԵ - -% if nargin > 2 - % I = preprocess(I, varargin{:}); -% end - -if isstr(I) - I = imread(I); -end - -[lineL, lineR]= im2boundaryline(I); - -% עⲻǾֵ -% Ȱվֵ -theta = 180 - (lineL.theta + lineR.theta)/2; % 90 - theta -% PointL = lineL.point2; -% PointR = lineR.point2; -% PointM = PointL/2.0 + PointR/2.0; %Left Middle Right -% PointO = lineL.point1; - -% % עthetahoughlinethetaͬ -% thetaL = atan( (PointL(2) - PointO(2) )/(PointL(1) - PointO(1) ) )*360/pi; -% thetaR = atan( (PointR(2) - PointO(2) )/(PointR(1) - PointO(1) ) )*360/pi; -% theta = atan( (PointM(2) - PointO(2) )/(PointM(1) - PointO(1) ) )*360/pi; - -thetaL = 180 - lineL.theta; -thetaR = 180 - lineR.theta; -Gray = rgb2gray(I); - -sigma = 3; -Wx = floor((5/2)*sigma); -%x = [-Wx:Wx]; -x = [Wx:-1:1, 0 1:Wx]; -% Զ˲ģ -% h.g = exp(-(x.^2)/(2*sigma^2)); -% h.gp = -(x/sigma).*h.g;% -(x/sigma).*exp(-(x.^2)/(2*sigma^2)); -% h.gp = -(x/(sigma^2)).*h.g;% -(x/sigma).*exp(-(x.^2)/(2*sigma^2)); -% h.theta = theta; %-theta*(180/pi); -% h.sigma = sigma; -% DLD -% y = 0 ˻һά -% h.g = ( (16*x.^4)/(sigma^8) - (48*x.^2)/(sigma^6) - 12/(sigma^4) ) .* exp(-(x.^2)/(sigma^2)); -% h.gp = ( (64*x.^3)/(sigma^8) - (96*x)/(sigma^6) ) .* exp(-(x.^2)/(sigma^2)) + ... - % h.g .* (-2*x/(sigma^2)); % -(x/sigma).*exp(-(x.^2)/(2*sigma^2)); -% h.g = ( (4*x.^2)/(sigma^4) - 2/(sigma^2) ) .* exp(-(x.^2)/(sigma^2)); -% h.gp = ( (8*x)/(sigma^8) ) .* exp(-(x.^2)/(sigma^2)) + ... - % h.g .* (-2*x/(sigma^2)); -h.g = ( (4*x)/(sigma^4) ) .* exp(-(x.^2)/(sigma^2)); -h.gp = ( 4/(sigma^4) ) .* exp(-(x.^2)/(sigma^2)) ... - + h.g .* (-2*x/(sigma^2)); -h.theta = theta; %0; %-theta*(180/pi); 0 -h.sigma = sigma; - -% [J,H] = steerGauss(Gray,theta,3,true); -J = steerGauss(Gray,h,true); -figure; -implot(I, J, J>0.2*max(J(:))); - -% function J = steerGauss(I,Wsize,sigma,theta) -% % USAGE: -% % Wsize = 20;sigma = 1;%Wsize = 7; -% % steerGauss(Gray,Wsize,sigma,theta); - -% % οhttp://blog.163.com/yuyang_tech/blog/static/216050083201302324443736/ -% % Ƕת[0,pi]֮ -% theta = theta/180*pi; -% % ά˹x,yƫgx,gy -% k = [-Wsize:Wsize]; -% g = exp(-(k.^2)/(2*sigma^2)); -% gp = -(k/sigma).*exp(-(k.^2)/(2*sigma^2)); -% gx = g'*gp; -% gy = gp'*g; -% % ͼx,y˲ -% Ix = conv2(I,gx,'same'); -% Iy = conv2(I,gy,'same'); -% % ͼtheta˲ -% J = cos(theta)*Ix+sin(theta)*Iy; - -% % figure,imshow(J); -% figure, -% subplot(1,3,1),axis image; colormap(gray);imshow(I),title('ԭͼ'); -% subplot(1,3,2),axis image; colormap(gray);imshow(cos(theta)*gx+sin(theta)*gy),title('˲ģ'); -% subplot(1,3,3),axis image; colormap(gray);imshow(J),title('˲'); \ No newline at end of file diff --git a/my_vehicle_vision_util/vvGetFeature.m b/my_vehicle_vision_util/vvGetFeature.m deleted file mode 100644 index 885f5aa..0000000 --- a/my_vehicle_vision_util/vvGetFeature.m +++ /dev/null @@ -1,85 +0,0 @@ -function FeatureMap = vvGetFeature(I, feature, preprocess, varargin) -%VVGETFEATURE -% USAGE: -% vvGetFeature('pictures/lanemarking/light_singlelane.jpg', 'light'); -% 可添加预处理 -% foreach_file_do( 'pictures/lanemarking/*.picture', ... - % @vvGetFeature, 'light', ... - % @vvPreprocess ... -% ); - -% http://cn.mathworks.com/help/vision/examples.html -if nargin > 2 - I = preprocess(I, varargin{:}); % 如果有预处理步骤,则先进行预处理 -end - -I = im2gray(I); % 确保图像为灰度图 -[numRow, numColumn] = size(I); % 注意:如果I不是灰度图像会出错 - -switch upper(feature) - -% 每一行独立地进行滤波,滤波器的大小跟随透视效应改变 -% 使用一维的滤波方式 -case {'LT', 'MLT', 'PLT', 'SLT'} - Filtered = vvRowFilter(I, feature); - FeatureMap = I - Filtered; - -case '1d-dld' - % noise: shadows - width = size(I, 2); - w = ceil(width/35); % width of road % 35太大丢失车道线 - - % DLD 1:2:1 - % w = 2 : [-1 -1 1 1 1 1 -1 -1]/2 - % w 大了噪声大;小了标记线裂开,分成两个边缘 - template_DLD = ones(1, 2*w); - template_DLD(1:ceil(w/2)) = -1; - template_DLD(ceil(w*3/2):w*2) = -1; - - % 好处是滤波后道路宽度固定 - DLD = imfilter(I, template_DLD, 'corr', 'replicate'); - %figure;imshow(DLD); - % Binary = DLD; - Binary = im2bw(DLD, 254/255); % 无需二值化就很明显了 - Binary = bwareaopen(Binary, ceil(width*7/3) ); - - % 左右不平均问题 -case 'tripoint' - width = size(I, 2); - w = ceil(width/35); % width of road % 35太大丢失车道线 - - for r = 1: size(I, 1) %size(I, 1) : -1 : 1 % 1: height - for c = w + 1 : width - w - % DLD(r, c) = Gray(height - r + 1 , c); % upside down - - % 三点式效果很差 - % 道路宽度改为固定值DLD特征公式 Utilizing Instantaneous Driving Direction for Enhancing Lane-Marking Detection - DLD(r, c) = 2 * I(r, c) - ( I(r, c - w) + I(r, c + w) ) - abs(I(r, c - w) - I(r, c + w)); - end - end - - % threshold = graythresh(DLD); - Binary = im2bw(DLD, 100/255); % 无需二值化就很明显了 - -case 'light' - % threshold = 200;%200; - % I(I < threshold) = 0; - % I(I >= threshold) = 1; - % Binary = logical(I); - threshold = graythresh(I); - Binary = im2bw(I, threshold); - Binary = bwareaopen(Binary, 300 ); - -case 'histeq' - I = histeq(I); - % threshold = graythresh(I); - Binary = im2bw(I, 243/255); - -case 'edge' - Binary = edge(I, 'sobel'); - -otherwise - error('Unknown feature to be extracted.'); -end - -% Binary = bwareaopen(Binary, 200); % 滤去孤立点 \ No newline at end of file diff --git a/my_vehicle_vision_util/vvGetLaneMarking.m b/my_vehicle_vision_util/vvGetLaneMarking.m deleted file mode 100644 index 082f58a..0000000 --- a/my_vehicle_vision_util/vvGetLaneMarking.m +++ /dev/null @@ -1,150 +0,0 @@ -clear all; - -% weark shadow -folder = 'LRAlargeur13032003'; -no = '02210'; - -%strong shadow -folder = 'BDXD54'; -no = '00071'; - -folder = ['dataset\roma\', folder]; -Original = imread([folder, '\IMG', no, '.jpg']); -GroundTruth = imread([folder, '\RIMG', no, '.pgm']); - -%灰度直方图 对标记线局部进行灰度直方图统计 -% imhist(GroundTruth); -% 255 0 -% figure;implot(Original, GroundTruth);return; -% 测试 -numRow = size(Original, 1); -numColumn = size(Original, 2); - -%扫描某一行,得出该行的灰度特征RGB分开? - -% Original = rgb2hsv(Original); - -r = 820; %scan -X = 1:numColumn; -R = Original(r,:,1); -G = Original(r,:,2); -B = Original(r,:,3); - -MIN = min(R,G); - - -% CurRow = Original; -% CurRow(r,:,:) = 255; -% CurRow = repmat(rgb2gray(Original(r,:,:)), [1, 100]); - -figure; -subplot(2,2,1);plot(X,R); -subplot(2,2,2);plot(X,G); -subplot(2,2,3);plot(X,B); -subplot(2,2,4);imshow(Original);hold on;plot([1, numColumn],[r, r], 'r-'); -return; - - - - -for c = 1:numColumn - if(GroundTruth(r,c) == 255) - - else - end -end - - -horizon = 310; % param.cal -I = vvPreprocess(Original, horizon); -numColumn = size(I, 2); -numRow = size(I, 1); - -NearField = I(end*2/3:end, end/5:end*4/5); -implot(I, NearField, NearField>210, I>210); -figure; -imhist(NearField); -return; - -% 滤波后反而分辨性下降 -% 先进行透视范围平均,标记内部均匀化处理,移动平均处理 如果差值不大,则取平均值 -% 滑动平均 -% Filtered = I; -% for r = 1:numRow -% for c = 1: numColumn-1 -% if abs(Filtered(r,c) - Filtered(r,c+1)) < 40 % 基本除了边界都能作用到 -% Filtered(r,c) = Filtered(r,c)/2+ Filtered(r,c+1)/2; -% end -% end -% end - -% figure; -% implot(I, Filtered); -% return; -% Original = Filtered; - -% L, ML, MR, R - -% 先看单行 - -% 当前行不一定存在 -inMarking = false; -index = 0; -for r = 1: numRow - for c = 1: numColumn - if ~inMarking - if GroundTruth(r,c) == 255 - % 左边界 - index = index + 1; - X(index) = r; - - L(index) = Original(r,c-2); - ML(index) = Original(r,c+1); - inMarking = true; - end - else % inMarking - if GroundTruth(r,c) == 0 - % 右边界 - R(index) = Original(r,c+2); - MR(index) = Original(r,c-1); - inMarking = false; - else - % inMarking - end - end - end -end -hold on; -size(X) -size(L) -size(R) -plot(X, L, 'r*'); -plot(X, ML, 'bo'); -plot(X, ML-L, 'y^'); -% plot(X, MR, 'bo'); -% plot(X, R, 'r*'); - -return; - -Dx = I(:,1:end-1) - I(:,2:end); -% Dx = [Dx, zeros(numRow-horizon, 1)]; % 补充最后一列 - -% I(:,1:end-1)>I(:,2:end)+20 导数一定门限 - -I_double = double(I); -% EdgeR = I_double(:,1:end-1) ./ I_double(:,2:end); % 非零 -w = 10; -% EdgeR = I_double(:,1:end-w) ./ I_double(:,1+w:end); % 非零 -EdgeR = (I_double(:,1:end-w) - I_double(:,1+w:end)) ./ I_double(:,1+w:end); % 非零 -nColEdgeR = size(EdgeR, 2); - -width_marking = 50; -for r = 1 : numRow - s = ceil(5 + r*width_marking/numColumn); % DLD使用 - % for c = s : numColumn - s - - Marking(r,(1+s)/2:nColEdgeR-s/2) = EdgeR(r, 1:end-s) - EdgeR(r, 1+s:end); - % end -end - -implot(EdgeR, Marking); \ No newline at end of file diff --git a/my_vehicle_vision_util/vvGetLine.m b/my_vehicle_vision_util/vvGetLine.m deleted file mode 100644 index 410dfda..0000000 --- a/my_vehicle_vision_util/vvGetLine.m +++ /dev/null @@ -1,58 +0,0 @@ -function lines = vvGetLine(I, method, getFeature, varargin) -%VVGETLINE get lines from a binary feature map. -% USAGE: -% VVGETLINE('pictures/lanemarking/light_singlelane.jpg', 'hough', ... -% @vvGetFeature, '1d-dld', ... -% @vvPreprocess); -% VVGETLINE('pictures/lanemarking/light.jpg', 'hough', ... -% @vvGetFeature, 'light', ... -% @vvPreprocess); - - -% http://cn.mathworks.com/help/vision/examples.html - -% foreach_file_do( 'pictures/lanemarking/*.picture', - % @getFeature, 'gray' - % @impreprocess, -% ); - -if nargin > 2 - I = getFeature(I, varargin{:}); % 如果有预处理步骤,则先进行预处理 -end - -% todo:此处I需要为灰度或二值图 - -% 不能直接检测 -% 提取出区域 区域中心还是? -% 腐蚀成一条线, -% 边缘检测有很多方法 -BW = edge(I, 'canny'); - -switch method -case 'hough' - %Hough Transform - [H,theta,rho] = hough(BW); - - % Finding the Hough peaks (number of peaks is set to 10) - P = houghpeaks(H,2,'threshold',ceil(0.2*max(H(:)))); - x = theta(P(:,2)); - y = rho(P(:,1)); - - %Fill the gaps of Edges and set the Minimum length of a line - lines = houghlines(BW,theta,rho,P,'FillGap',170,'MinLength',50); - - % Plotting the relevant lines - figure; - Lines = I; - implot(I, Lines); - for i = 1:length(lines) - xy = [lines(i).point1; lines(i).point2]; - hold on; - plot(xy(:,1),xy(:,2),'LineWidth',5,'Color','red'); - end - -otherwise - error('unknown line detection method.'); -end - -% hough变换演示 \ No newline at end of file diff --git a/my_vehicle_vision_util/vvGetRoadFace.m b/my_vehicle_vision_util/vvGetRoadFace.m deleted file mode 100644 index 84512b2..0000000 --- a/my_vehicle_vision_util/vvGetRoadFace.m +++ /dev/null @@ -1,278 +0,0 @@ -function RoadRegion = vvGetRoadFace(image) -% 不再维护 -% 返回近视野路面的鸟瞰灰度图(颜色信息用不上) -% 降低分辨率便于处理,提高处理效果。检测精度问题? -% 用低分辨率处理, -% 得到路面区域再回到高分辨率 注意图像回到高分辨率会出现锯齿,但参数不会,所以在低分辨率提取参数是可行的 -% 或者变化分辨率 -% 大量阴影 -% dataset\roma\BDXD54\IMG00071.jpg -% dataset\roma\BDXD54\IMG00030.jpg -% foreach_file_do('dataset\roma\BDXD54\*.jpg',@vvGetRoadFace) - -% 先对图像做倒转,不然坐标变换太麻烦 - -if isstr(image) - disp(['start processing image:', image]); - image = imread(image); -end - -isresize = false; -% 改为处理边界时用resize的图,resize放到边界处理内部,得出参数后进行投射变换 -if isresize == true - numRow = 150; - numColumn = 200; - image = imresize(image, [numRow, numColumn]); -else - [numRow, numColumn, nchannel] = size(image); -end - -if nchannel ~= 3 - error('input must be a colour image.'); -end - -[horizon, PointO, PointL, PointR] = detectRoadBoundary(image); -image = rgb2gray(image); -RoadRegion = perspectiveTrans(image, horizon, PointO, PointL, PointR); -imdump(RoadRegion); - -%-------------------------------------------------------------------% -% ISM2015 中为提取左右边界,这里只提取三个特殊点,从而进行投影变换 -% 其他参数可以通过这三个点求得 -function [horizon, PointO, PointL, PointR] = detectRoadBoundary(original) - -[height, width, nchannel] = size(original); - -numRow = 150; %min(height, 150); -numColumn = 200; %min(width, 200); - -image = imresize(original, [numRow, numColumn]); - -horizon = ceil(numRow /3); % numRow/2; -left = zeros(horizon); -right = numColumn * ones(horizon); -theta = [-89:89]; - -%% image preprocessing -% 很有可能下半部分全是阴影,使得检测无法进行 -ROI = image( horizon:end,:,:); -% ROI = RGB; - -[RGB_R, RGB_G, RGB_B] = getChannel(ROI); -RGB_min = min(min(RGB_R, RGB_G) , RGB_B); -RGB_max = max(max(RGB_R, RGB_G) , RGB_B); -S_modified = double(RGB_max - RGB_B) ./ double(RGB_max + 1); - -% road boundary detection -% 阈值要足够高 0.3 -% 改进:左侧,右侧独立进行阈值化,防止单边的影响!确保两侧都有!可以处理图像左右光照不对称的情形 -% S_bw = S_modified > 0.5*max(S_modified(:)); -% S_bw = imclose(S_bw, strel('square',3)); %imdilate imclose imopen -% S_bw = bwareaopen(S_bw, 500); - -S_L = S_modified(:,1:floor(numColumn/2)); -S_R = S_modified(:,floor(numColumn/2)+1:end); % 注意不能写ceil ceil可能等于floor - -S_bw_L = S_L > 0.45*max(S_L(:)); % 0.3 0.2 % 用histeq和graythresh效果不好 -S_bw_L_imclose = imclose(S_bw_L, strel('square',3)); %imdilate imclose imopen -S_bw_L_areaopen = bwareaopen(S_bw_L_imclose, 200); % 去除车道线 - -S_bw_R = S_R > 0.45*max(S_R(:)); -S_bw_R_imclose = imclose(S_bw_R, strel('square',3)); -S_bw_R_areaopen = bwareaopen(S_bw_R_imclose, 200); - -S_bw = [S_bw_L_areaopen, S_bw_R_areaopen]; - -imdump(S_modified, S_bw,... - S_bw_L, S_bw_L_imclose, S_bw_L_areaopen,... - S_bw_R, S_bw_R_imclose, S_bw_R_areaopen); - - -[BoundaryL, BoundaryR] = bwExtractBoundaryPoints(S_bw); -RemovedRegion = zeros(horizon-1, numColumn); % 为了正确显示直线,补上去掉的区域 -lineL = bwFitLine([RemovedRegion; BoundaryL], [0:89]); -lineR = bwFitLine([RemovedRegion; BoundaryR], [-89:0]); - -% lineL = bwFitLine(BoundaryL); -% lineR = bwFitLine(BoundaryR); - -try - thetaL = lineL.theta; - thetaR = lineR.theta; - theta = [ceil(min(thetaL, thetaR)):floor(max(thetaL, thetaR))]; -catch ME -% 直线没有找到的情形 - % debug - lineL - lineR - % close all; - figure; - implot(RGB, S_modified, S_bw, BoundaryL, BoundaryR); - error(['Sorry, no boundary is found!']); - return; -end - -PointO = linemeetpoint( lineL.point1, lineL.point2, lineR.point1, lineR.point2 ); -PointL = linemeetpoint( lineL.point1, lineL.point2, [1, numRow], [2, numRow]); -PointR = linemeetpoint( lineR.point1, lineR.point2, [1, numRow], [2, numRow]); - -% 绘图 先划线 -h = implot(original, image); -title('detected'); -% left and right boundary line -plotline(PointO, PointL,'LineWidth',3,'Color','yellow'); -plotline(PointO, PointR,'LineWidth',3,'Color','green'); -% horizon line -plotline([1, PointO(2)], [numColumn, PointO(2)], 'LineWidth',3,'Color','blue'); -% vanishing point -plot(PointO(1), PointO(2), 'ro', 'markersize', 10); -% 水平线horizon 把消失点所在的水平位置设为地平线 -plot(PointL(1), PointL(2), 'r*'); -plot(PointR(1), PointR(2), 'r*'); -% feature points -for r = horizon : numRow % 1 : (numRow/2) - for c = 1 : numColumn - if 1 == BoundaryL(r - horizon + 1, c) - plot(c, r, 'y+'); - end - if 1 == BoundaryR(r - horizon + 1, c) - plot(c, r, 'g+'); - end - end -end -imdump(h); - -% 等前面 horizon 用完 -horizon = floor(PointO(2)); % Notice: 特殊图片: horizon为负数 消失点在图像外 - -% 左右边界用不上了 -% h = numRow - horizon + 1; % horizon : numRow -% for r = 1 : numRow -% left(r) = ceil( PointO(1) - (PointO(1) - PointL(1))* r / h); -% right(r) = ceil( PointO(1) + (PointR(1) - PointO(1))* r / h); -% end - -% 还原resize带来的影响 -horizon = ceil(horizon*height/numRow); - -PointO(1) = PointO(1)*width/numColumn; -PointO(2) = PointO(2)*height/numRow; -PointL(1) = PointL(1)*width/numColumn; -PointL(2) = PointL(2)*height/numRow; -PointR(1) = PointR(1)*width/numColumn; -PointR(2) = PointR(2)*height/numRow; - -function Transformed = perspectiveTrans(image, horizon, PointO, PointL, PointR) -% RoadFace为水平线以下的区域 -% 三个特征点还原到大图的水平线以下 - -ischop = false; % 裁剪得越多,可用的数据越少? true; % - -if ischop - % 裁剪掉水平线以上部分 - % horizon = 300; - I = image(horizon:end,:,:); - % 点的坐标调整 - PointO(2) = PointO(2) - horizon; - PointL(2) = PointL(2) - horizon; - PointR(2) = PointR(2) - horizon; - % 裁剪后的坐标调整结束 -else - I = image; -end - -[numRow, numColumn, nchannel] = size(I); - -% 透视变换 -PointLU = PointO/2 + PointL/2; -PointRU = PointO/2 + PointR/2; - -% 显示特征点 -% figure;subplot(1,2,1);imshow(I);hold on; -% plot(PointLU(1), PointLU(2), 'yo', 'markersize', 10); -% plot(PointRU(1), PointRU(2), 'bo', 'markersize', 10); -% plot(PointL(1), PointL(2), 'y*', 'markersize', 10); -% plot(PointR(1), PointR(2), 'b*', 'markersize', 10); - -% % 求变换矩阵: -% TForm = cp2tform(B,A,'projective'); -% round(tformfwd(TForm,[400 240]));% 每个点对应到新的位置 - -B = [PointLU;PointRU; PointL;PointR];% 源图像中的点的坐标矩阵为: 点在图像外 -% 透视结果仅仅是拉伸 -% 还原成大小 50*100 150*200 -% outCols = 100; outRows = 50; -outCols = 80; outRows = 60; % 三个像素宽度 -% outCols = 40; outRows = 30; % 一个像素宽度 - -% TODO:改为仅对所选区域变换 -A = [1, 1;outCols,1;1,outRows;outCols, outRows]; -% 太大了,造成响应慢 生成更大的空间 7988*6241 A = [1, 1;numColumn,1;1,numRow;numColumn, numRow];% 目标图像中对应的顶点坐标为: - -tform = fitgeotrans(B, A, 'projective'); -% tform = cp2tform(B,A,'projective'); -Transformed = imwarp(I,tform, 'OutputView', imref2d([outRows, outCols])); - -%-------------------------------------------------------------------% -function line = bwFitLine(BW, Theta) -%Hough Transform -if nargin < 2 - [H,theta,rho] = hough(BW); -else - [H,theta,rho] = hough(BW, 'Theta', Theta); -end - -% Finding the Hough peaks -P = houghpeaks(H, 1); -x = theta(P(:,2)); -y = rho(P(:,1)); - -%Fill the gaps of Edges and set the Minimum length of a line -lines = houghlines(BW,theta,rho,P, 'MinLength',10, 'FillGap',570); -line = lines(1); - -% figure; -% imshow(H,[],'XData',theta,'YData',rho,'InitialMagnification','fit'); -% xlabel('\theta'), ylabel('\rho'); -% axis on, axis normal, hold on; -% plot(theta(P(:,2)),rho(P(:,1)),'s','color','white'); -% figure; - -%-------------------------------------------------------------------% -function [BoundaryL, BoundaryR] = bwExtractBoundaryPoints(BW) -[numRow, numColumn] = size(BW); - -Boundary_candidate = zeros(numRow, numColumn); -BoundaryL = zeros(numRow, numColumn); -BoundaryR = zeros(numRow, numColumn); -ScanB = zeros(numRow, numColumn); -ScanL = zeros(numRow, numColumn); -ScanR = zeros(numRow, numColumn); - -for c = 1 : numColumn - for r = numRow : -1 : 1 - if 1 == BW(r, c) - Boundary_candidate(r, c) = 1; - break; - end - ScanB(r, c) = 1; - end -end -for r = numRow : -1 : 1 - for c = ceil(numColumn/2) : -1 : 1 - if 1 == Boundary_candidate(r, c) - BoundaryL(r, c) = 1; - break; - end - ScanL(r, c) = 1; - end - for c = floor(numColumn/2) : numColumn - if 1 == Boundary_candidate(r, c) - BoundaryR(r, c) = 1; - break; - end - ScanR(r, c) = 1; - end -end - -imdump(Boundary_candidate, BoundaryL, BoundaryR); \ No newline at end of file diff --git a/my_vehicle_vision_util/vvGetVp.m b/my_vehicle_vision_util/vvGetVp.m deleted file mode 100644 index 4a078fb..0000000 --- a/my_vehicle_vision_util/vvGetVp.m +++ /dev/null @@ -1,89 +0,0 @@ -function [VP, linesL, linesR] = vvGetVp(im, lastVP) -%VVGETVP locates Vanishing-point from an input road scene image. - -% vvGetVp(im); - -%% parameter setting -% precision of location: (0,1] smaller to avoid false detecting, bigger to improve accuracy. -precisionVP = 0.4; - -[nRow, nCol, ~] = size(im); -if nargin < 2 - lastVP = [floor(nCol/2), floor(nRow/2)]; -end - -%% line segment detection -% divide image to parts according to the location of VP detected in last frame. -RoadL = im(lastVP(2):end, 1:lastVP(1)); -RoadR = im(lastVP(2):end, lastVP(1)+1:end); - -% detect line segments separately. -[lineSegmentsL, noOfSegmentsL]= EDLines(RoadL, 1); -[lineSegmentsR, noOfSegmentsR]= EDLines(RoadR, 1); - -% filter lines according to their angle. -lineFilterAngleL = [LineObj([0 0],[0 0])]; -lineFilterAngleR = [LineObj([0 0],[0 0])]; - -for i = 1:noOfSegmentsL - lineAngle = lineSegmentsL(i).a; - lineSegmentsL(i).move([lastVP(2)-1, 0]); - if lineAngle > -75 && lineAngle < -30 - lineFilterAngleL(end+1) = lineSegmentsL(i); - end -end -for i = 1:noOfSegmentsR - lineAngle = lineSegmentsR(i).a; - lineSegmentsR(i).move([lastVP(2)-1, lastVP(1)]); - if lineAngle > 30 && lineAngle < 75 - lineFilterAngleR(end+1) = lineSegmentsR(i); - end -end - -% plot candidate line segments. -LinesDetection = implot(im); -plotobj(lineSegmentsL, lineSegmentsR, lineFilterAngleL, lineFilterAngleR); -imdump(LinesDetection); - -%% Vote for VP -% initialize parameters. -VoteVP = zeros(ceil(nRow*precisionVP),ceil(nCol*precisionVP)); -VoteVP_L = zeros(size(VoteVP)); -VoteVP_R = zeros(size(VoteVP)); - -for i = 1:length(lineFilterAngleL) - VoteVP_L = VoteVP_L + lineFilterAngleL(i).path([nRow, nCol], size(VoteVP)); -end -for i = 1:length(lineFilterAngleR) - VoteVP_R = VoteVP_R + lineFilterAngleR(i).path([nRow, nCol], size(VoteVP)); -end - -% plot vote results. -VoteVP = VoteVP_L .* VoteVP_R; -[maxVoteVP, index] = max(VoteVP(:)); -VP = [ mod(index,size(VoteVP,1))/precisionVP, ceil(index/size(VoteVP,1)/precisionVP) ]; - -VpDetection = implot(im, VoteVP_L, VoteVP_R, VoteVP); -hold on; plot(ceil(index/size(VoteVP,1)),mod(index,size(VoteVP,1)),'yo'); -selplot('im'); -hold on; plot(VP(2), VP(1), 'y+'); -imdump(VoteVP_R, VoteVP_L, VoteVP, VpDetection); - -%% LaneDetection according to the orientation of lines. -lineFilterPassVpL = [LineObj([0 0],[0 0])]; -lineFilterPassVpR = [LineObj([0 0],[0 0])]; -for i = 1:length(lineFilterAngleL) - if lineFilterAngleL(i).distance2point(VP) < 1/precisionVP - lineFilterPassVpL(end+1) = lineFilterAngleL(i); - end -end -for i = 1:length(lineFilterAngleR) - if lineFilterAngleR(i).distance2point(VP) < 1/precisionVP - lineFilterPassVpR(end+1) = lineFilterAngleR(i); - end -end - -% plot candidate line segments. -LaneDetection = implot(im); -plotobj(lineFilterAngleL, lineFilterAngleR, lineFilterPassVpL, lineFilterPassVpR); -imdump(LaneDetection); diff --git a/my_vehicle_vision_util/vvMarkFeature.m b/my_vehicle_vision_util/vvMarkFeature.m deleted file mode 100644 index e3a8a98..0000000 --- a/my_vehicle_vision_util/vvMarkFeature.m +++ /dev/null @@ -1,102 +0,0 @@ -% function FeatureMap = vvMarkFeature(I, feature) - -% RawImg = imread('.\IMG00021.jpg'); -RawImg = imread('shadowy_road.jpg'); - - - - - -% 通过真值进行训练,学习?————需要靠谱的特征 - - -DldFeature = zeros(nRow, nCol); -for r = 1:nRow - for c = 1:w:nCol - % default c1,c2 - c1 = c; - c2 = c+w; - - [~, c1] = max(LeftEdge(r,c,c+w)); - [~, c2] = max(RightEdge(r,c,c+w)); - DldFeature(r, c1:c2) = 1; - end -end - -global dumppathstr; -dumppathstr = 'F:/Documents/MATLAB/output/'; -imdump(LeftEdge, RightEdge); -return; - -BW = Filtered > 0.8*max(Filtered(:)); -laneMark = bwareaopen(BW,8,4); - - - -switch upper(feature) - -% 每一行独立地进行滤波,滤波器的大小跟随透视效应改变 -% 使用一维的滤波方式 -case {'LT', 'MLT', 'PLT', 'SLT'} - Filtered = vvRowFilter(I, feature); - FeatureMap = I - Filtered; - -case '1d-dld' - % noise: shadows - width = size(I, 2); - w = ceil(width/35); % width of road % 35太大丢失车道线 - - % DLD 1:2:1 - % w = 2 : [-1 -1 1 1 1 1 -1 -1]/2 - % w 大了噪声大;小了标记线裂开,分成两个边缘 - template_DLD = ones(1, 2*w); - template_DLD(1:ceil(w/2)) = -1; - template_DLD(ceil(w*3/2):w*2) = -1; - - % 好处是滤波后道路宽度固定 - DLD = imfilter(I, template_DLD, 'corr', 'replicate'); - %figure;imshow(DLD); - % Binary = DLD; - Binary = im2bw(DLD, 254/255); % 无需二值化就很明显了 - Binary = bwareaopen(Binary, ceil(width*7/3) ); - - % 左右不平均问题 -case 'tripoint' - width = size(I, 2); - w = ceil(width/35); % width of road % 35太大丢失车道线 - - for r = 1: size(I, 1) %size(I, 1) : -1 : 1 % 1: height - for c = w + 1 : width - w - % DLD(r, c) = Gray(height - r + 1 , c); % upside down - - % 三点式效果很差 - % 道路宽度改为固定值DLD特征公式 Utilizing Instantaneous Driving Direction for Enhancing Lane-Marking Detection - DLD(r, c) = 2 * I(r, c) - ( I(r, c - w) + I(r, c + w) ) - abs(I(r, c - w) - I(r, c + w)); - end - end - - % threshold = graythresh(DLD); - Binary = im2bw(DLD, 100/255); % 无需二值化就很明显了 - -case 'light' - % threshold = 200;%200; - % I(I < threshold) = 0; - % I(I >= threshold) = 1; - % Binary = logical(I); - threshold = graythresh(I); - Binary = im2bw(I, threshold); - Binary = bwareaopen(Binary, 300 ); - -case 'histeq' - I = histeq(I); - % threshold = graythresh(I); - Binary = im2bw(I, 243/255); - -case 'edge' - Binary = edge(I, 'sobel'); - -otherwise - error('Unknown feature to be extracted.'); -end - -% Binary = bwareaopen(Binary, 200); % 滤去孤立点 \ No newline at end of file diff --git a/my_vehicle_vision_util/vvPreprocess.m b/my_vehicle_vision_util/vvPreprocess.m deleted file mode 100644 index e5b9719..0000000 --- a/my_vehicle_vision_util/vvPreprocess.m +++ /dev/null @@ -1,60 +0,0 @@ -function Preprocessed = vvPreprocess(image, horizon) -% numRow = size(I, 1); -% numColumn = size(I, 2); -% vvPreprocess(image, [ceil(numRow/2):numRow;1:numColumn]); % low half -% vvPreprocess(image, [horizon:numRow;1:numColumn]); % lower than horizontal line - - -Gray = im2gray(image); - -% ROI不一定取某条线以下,应该是个横轴和纵轴的范围,表征一个矩形 [x1,x2;y1,y2] -% Gray = image(ceil(end/2):end, :); - -if nargin < 2 - Preprocessed = Gray(ceil(end/2):end, :); -else - Preprocessed = Gray(horizon:end, :); -end - -% 先裁剪 运算较复杂,但不要求精度,可以先将图片缩小,得到坐标后,再放大 -% 分析RGB分量图 观察1-255的值的变化,直方图分布情况 -% 道路区域RG值 - -% 即调节系数 -% R G B 转灰度图的系数 -% Gray = R G B - -% 看颜色分布 -% HSV也尝试一下 涉及复杂的颜色空间转换 -% 为了提高图像增强效果,可以采用训练优化参数,评价模型 -% 使得车道线更加突出 - -% 颜色空间的介绍和选取 - -% 直方图的实验 - -% 我们知道红+绿=黄 红+绿+蓝=白 -% 提取出车道线,可以选定 红+绿 -% 比例调整 - -% 对比度调节,白天夜晚的同一场景需要近似输出 - - -% 实验方法 - - -% - -% 为了获得干净的二值特征图, - -% 白平衡处理去除色彩失真 -% 灰度化,突出车道,过滤光照因素的影响 -% 灰度图(阈值化时动态阈值) 建议通过直方图(像素统计信息)选定阈值分割 道路占较大面积 -% 提取出图像中的车道-特征提取往往 是否属于车道 -% 直线拟合或曲线拟合中心两侧的第一条车道线(可能有多车道,其他车道无需拟合) - - diff --git a/my_vehicle_vision_util/vvRowFilter.m b/my_vehicle_vision_util/vvRowFilter.m deleted file mode 100644 index 028bc7b..0000000 --- a/my_vehicle_vision_util/vvRowFilter.m +++ /dev/null @@ -1,78 +0,0 @@ -function Filtered = vvRowFilter(I, method, preprocess, varargin) -%vvRowFilter - -% 考虑透视效应,行滤波器的大小线性地调整 - -if nargin > 2 - I = preprocess(I, varargin{:}); % 如果有预处理步骤,则先进行预处理 -end - -I = im2gray(I); % 确保图像为灰度图 -[numRow, numColumn, ~] = size(I); - -method = upper(method); - -switch method -case 'DLD' - I = double(I); % 含有负数 -end - -Filtered = I; % 均值滤波去除掉车道标记 - -for r = 1 : numRow - % horizon - 5 numColumn - 512 - % s = ceil(5 + r*250/numColumn); % 100过滤不掉,300可以 - s = ceil(5 + r*50/numColumn); % DLD使用 - - switch method - % 每一行独立地进行滤波,滤波器的大小跟随透视效应改变 - % 使用一维的滤波方式 - case 'LT' % 均值滤波 - Filtered(r,:) = imfilter(I(r,:), ones(1, s)/s , 'corr', 'replicate'); - case 'MLT' % 中值滤波 - Filtered(r,:) = medfilt2(I(r,:), [1, s]); - case 'PLT' - case 'SLT' - % todo - case 'SMLT' - half_s = ceil(s/2); - Middle = medfilt2(I(r,:), [1, s]); - Middle = [repmat(Middle(1), [1,half_s]), Middle, repmat(Middle(end), [1,half_s])]; - Filtered(r,:) = Middle(1:end-half_s*2)/2 + Middle(1+half_s*2:end)/2; - - case 'DLD' % -1-1 1 1 1 1 -1 -1 - half_s = ceil(s/2); - template_DLD = ones(1, s*2); - template_DLD(1:half_s) = -1; - template_DLD(half_s*3:s*2) = -1; - Filtered(r,:) = imfilter(I(r,:), template_DLD, 'corr', 'replicate'); - - case '%TEST' % for testing - Mean = imfilter(I(r,:), ones(1, s)/s , 'corr', 'replicate'); - Middle = medfilt2(I(r,:), [1, s]); - LT(r,:) = Mean; - MLT(r,:) = Middle; - - % 扩充s/2 - half_s = ceil(s/2); - Mean = [repmat(Mean(1), [1,half_s]), Mean, repmat(Mean(end), [1,half_s])]; - Middle = [repmat(Middle(1), [1,half_s]), Middle, repmat(Middle(end), [1,half_s])]; - - % SLT(r,:) = (Mean(1:end-half_s*2) + Mean(1+half_s*2:end))/2; % 不转成double会越界 - SLT(r,:) = Mean(1:end-half_s*2)/2 + Mean(1+half_s*2:end)/2; - SMLT(r,:) = Middle(1:end-half_s*2)/2 + Middle(1+half_s*2:end)/2; - end - -end - -switch upper(method) -case '%TEST' -figure; -implot(LT, MLT, SLT, SMLT); -LT = I - LT; -MLT = I - MLT; -SLT = I - SLT; -SMLT = I - SMLT; -figure; -implot(LT, MLT, SLT, SMLT); -end \ No newline at end of file diff --git a/my_vehicle_vision_util/vvRowFilterTest.m b/my_vehicle_vision_util/vvRowFilterTest.m deleted file mode 100644 index fcc9044..0000000 --- a/my_vehicle_vision_util/vvRowFilterTest.m +++ /dev/null @@ -1,46 +0,0 @@ -function vvRowFilterTest(I, h, w) -% h - horizon -% w - lane-marking pixel width of last row - -[nRow, nCol, ~] = size(I); -if nargin < 3 - w = nCol/8; - if nargin < 2 - h = nRow/2; - end -end - -I = double(im2gray(I)); -ROI = I(h:end,:); -nRow = size(ROI, 1); - -LT = zeros(nRow, nCol); -MLT = zeros(nRow, nCol); -SLT = zeros(nRow, nCol); -SMLT = zeros(nRow, nCol); - -for r = 1 : nRow - s = ceil(5 + w*r/nCol); - Mean = imfilter(ROI(r,:), ones(1, s)/s , 'corr', 'replicate'); - Middle = medfilt2(ROI(r,:), [1, s]); - LT(r,:) = Mean; - MLT(r,:) = Middle; - - % extend image for computing the SLT and SMLT - half_s = ceil(s/2); - MeanExtend = [repmat(Mean(1), [1,half_s]), Mean, repmat(Mean(end), [1,half_s])]; - MiddleExtend = [repmat(Middle(1), [1,half_s]), Middle, repmat(Middle(end), [1,half_s])]; - SLT(r,:) = MeanExtend(1:end-half_s*2)/2 + MeanExtend(1+half_s*2:end)/2; - SMLT(r,:) = MiddleExtend(1:end-half_s*2)/2 + MiddleExtend(1+half_s*2:end)/2; -end - -implot(ROI, LT, MLT, SLT, SMLT); -maxfig; -LT = ROI - LT; -MMLT = medfilt2(ROI) - MLT; -MLT = ROI - MLT; -SLT = ROI - SLT; -SMLT = ROI - SMLT; -hold off; -implot(ROI, LT, MLT, SLT, SMLT, MMLT); -maxfig; \ No newline at end of file diff --git a/my_vehicle_vision_util/vvSegBound.m b/my_vehicle_vision_util/vvSegBound.m deleted file mode 100644 index 0a1d74a..0000000 --- a/my_vehicle_vision_util/vvSegBound.m +++ /dev/null @@ -1,172 +0,0 @@ -function BW = vvSegBound(RawImg) -% vvSegBound(imread('shadowy_road.jpg')); -% vvSegBound(imread('many.jpg')); - - -%% Extract feature map. (the probablity of being a boundary point. - - [RGB_R, RGB_G, RGB_B] = getChannel(RawImg); - RGB_max = max(max(RGB_R, RGB_G) , RGB_B); - RGB_min = min(min(RGB_R, RGB_G) , RGB_B); - - - S2 = double(RGB_max - RGB_B) ./ double(RGB_max + 1); - RpGm2B = RGB_R + RGB_G - 2 * RGB_B; - %H2 = double(RGB_G/2 + RGB_R/2) ./ double(RGB_B - RGB_min + 1); - %H2 = mat2gray(H2); - - implot(RawImg, S2, RpGm2B); - imdump(RpGm2B, S2); - thresh_tool(RpGm2B); - thresh_tool(S2); - return; - - - featureMap = im2uint8(mat2gray(S2)); - - -%% Segment. - - segment = @(x) im2bw(x, 0.1 + graythresh(x)); - - Seg = segment(featureMap); - - ratio = 0.02; - thumbnail = imresize(featureMap, ratio); % [32, 40] - Seg_small = segment(thumbnail); - - mask = imresize(Seg_small, size(featureMap)); - - Seg2 = Seg & mask; - - implot(RawImg, featureMap, Seg, mask, Seg2); - return; - -%% Extract bound points. - - - - % Edge based - H1 = [ 3, 1, 0; - 1, 0, -1; - 0, -1, -3]; - H2 = fliplr(H1); - - LeftBound = imfilter(featureMap,H1,'replicate'); - RightBound = imfilter(featureMap,H2,'replicate'); - - implot(RawImg, featureMap, Seg, LeftBound, RightBound, Seg&LeftBound); - return; - - -% test for segment - % segment2(RawImg(nHorizon+1:end,:,:),MaskRoadFace, MaskRoadBound); - - % function segment2(img, mask1, mask2) - % [L,P] = imseggeodesic(img,mask1,mask2); - - % implot(mask1, mask2, img); hold on; - % visboundaries(mask1,'Color','r'); - % visboundaries(mask2,'Color','b'); - - % figure - % imshow(label2rgb(L),'InitialMagnification', 50) - % title('Segmented image') - - % figure - % imshow(P(:,:,1),'InitialMagnification', 50) - % title('Probability that a pixel belongs to the foreground') - % end - - %% segmentation 2 - - % if RoadFaceClassifier is provided, then reject featureMap and use the classifier. - % if exist('RoadFaceClassifier', 'var') - % theclass = predict(RoadFaceClassifier, computeFeatureVector()); - % featureMap = reshape(theclass, nRow-nHorizon, nCol); - % end - -% vvSegBound(imread('shadowy_road.jpg')); - -% shadow's B is max : RGB_max == RGB_B - - - -S3 = double(RGB_R - RGB_B) ./ double(RGB_R + 1); -S4 = double(RGB_G - RGB_B) ./ double(RGB_G + 1); -S5 = S3/2 + S4/2; - -% Seg = im2bw(RpGmB, graythresh(RpGmB)); -Seg = im2bw(RawImg, graythresh(RawImg)); -%% Refine boundary points -% Remove shadows -Shadow = RGB_B == RGB_max; -ShadowMask = imdilate(Shadow, strel('square',3)); - -BW = Seg .* ~ShadowMask; % imclose the shadow to get better performance - -implot(RpGmB, RGB_min == RGB_B , (RGB_min == RGB_B)&(RGB_max == RGB_G)); - - -return; - -%RpGmB = RGB_R + RGB_G - 2 * RGB_B; % train the parameter k - - - - -% H = [ 1, 0, 0, 0, -1; -% 1, 0, 0, 0, -1; -% 4, 2, 0, -2, -4; -% 1, 0, 0, 0, -1; -% 1, 0, 0, 0, -1]; - -% H = [ 1 -1; -% 1 -1]; - -% GrayImg = RawImg(:,:,1); - -% -% LeftEdge = imfilter(GrayImg,-H,'replicate'); -% RightEdge = imfilter(GrayImg,H,'replicate'); -% -% implot(leftBound, RightBound, S2, RawImg); -% figure; -% implot(LeftEdge, RightEdge, S2, RawImg); - -% imshowedge(S2); - -S2_uint8 = im2uint8(mat2gray(S2)); - -leftBound = imfilter(S2_uint8,-H,'replicate'); -RightBound = imfilter(S2_uint8,H,'replicate'); - -figure; -% thresholdLocally is not suitable for this case -implot(thresholdLocally(RawImg), S2, RawImg, thresholdLocally(S2_uint8)); - -%% Edge detection -% -% % function [edgeSegments, noOfSegments] = ED(image, gradientThreshold, anchorThreshold, smoothingSigma) -% [edgeSegments, noOfSegments] = ED(S2_uint8, 60, 20, 1); -% % 20, 0, 1 -% -% figure; -% implot(S2, RawImg); % zeros(nRow, nCol) -% hold on; -% -% for i = 1:noOfSegments -% for j = 1:size(edgeSegments{i}, 1) -% plot(edgeSegments{i}(j, 1), edgeSegments{i}(j, 2), 'y*'); -% end -% end - -%% Line detection -% lineSegmentsRaw = EDLines(RawImg, 1); -% lineSegmentsAfter = EDLines(S2_uint8, 1); -% -% figure; -% implot(RawImg,S2_uint8); -% hold on; -% selplot(1);plotobj(lineSegmentsRaw); -% selplot(2);plotobj(lineSegmentsAfter);