Changeset 687
- Timestamp:
- 02/21/10 16:41:59 (2 years ago)
- Location:
- branches/2010-image-rec
- Files:
-
- 1 removed
- 3 modified
-
docs/report.pdf (modified) (previous)
-
hist_test.asv (deleted)
-
hist_test.m (modified) (11 diffs)
-
run.sh (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/2010-image-rec/hist_test.m
r683 r687 1 function hist_test(fn, show_images) 2 3 % Test how well histogramming works with our test images 4 %fn = 'images/course-walk/cimg4943.jpg'; 5 %fn = 'images/course-walk/cimg4921.jpg'; 6 %fn = 'images/elphel/cam-000078.jpeg'; 7 %$fn = 'images/elphel/cam-000086.jpeg'; % Hard image 8 %fn = 'images/course-walk/cimg4989.jpg'; 9 10 %fn = 'images/elphel/cam-000094.jpeg'; 11 fn = 'images/elphel/cam-000081.jpeg'; 12 13 fprintf('Running on %s... ', fn); 1 function hist_test(fn) 2 3 show_images = 1; 4 5 if show_images 6 close all; 7 %fn = 'images/course-walk/cimg4943.jpg'; 8 %fn = 'images/course-walk/cimg4921.jpg'; 9 %fn = 'images/elphel/cam-000078.jpeg'; 10 %$fn = 'images/elphel/cam-000086.jpeg'; % Hard image 11 %fn = 'images/course-walk/cimg4989.jpg'; 12 13 %fn = 'images/elphel/cam-000094.jpeg'; 14 fn = 'images/elphel/cam-000081.jpeg'; 15 end 16 17 fprintf('Running on %s...\n', fn); 14 18 15 19 % Number of bins in the histogram. … … 24 28 s_mean_factor = 0.2; % Seems to most effect obstacle detection 25 29 v_mean_factor = 0.1; % Obstacles and lines 26 t_mean_factor = 0.01;27 texture_band = 2;30 %t_mean_factor = 0.01; 31 %texture_band = 2; 28 32 29 33 im_rgb = imread(fn); … … 33 37 34 38 im = zeros(rows, cols, 4); 35 imbig = rgb2hsv(im_rgb);36 39 im_rgb = imresize(im_rgb, 0.25); 37 40 38 39 %fsobel = fspecial('sobel'); 40 %hedges = filter2(fsobel , imbig(:,:,texture_band)); 41 %vedges = filter2(fsobel', imbig(:,:,texture_band)); 42 %edges = sqrt(hedges .^ 2 + vedges .^ 2); 41 %fprintf('Sobelizing\n'); 43 42 edges = double(imread([fn '-sobel-v-5.png']))/255; 44 texture = filter2(fspecial('average', 10), edges); 45 texture = filter2(fspecial('average', 10), texture); 46 texture = filter2(fspecial('average', 10), texture); 47 texture = filter2(fspecial('average', 10), texture); 48 texture = filter2(fspecial('average', 10), texture); 49 texture = filter2(fspecial('average', 10), texture); 50 texture = filter2(fspecial('average', 10), texture); 51 texture = filter2(fspecial('average', 10), texture); 52 texture = filter2(fspecial('average', 10), texture); 53 texture = filter2(fspecial('average', 10), texture); 54 texture = filter2(fspecial('average', 10), texture); 43 44 fprintf('Blurring sobel\n'); 45 texture = imresize(edges, .25); 46 %texture = filter2(fspecial('average', 3), texture); 55 47 texture(texture > 1) = 1; 56 48 57 figure(1); 58 imwrite(texture, [fn '-texture-full.png']); 59 60 texture = imresize(texture, .25); 61 49 if show_images 50 figure('Name','Texture'), imshow(texture); 51 else 52 imwrite(texture, [fn '-texture.png']); 53 end 54 55 56 fprintf('Histogramming\n'); 62 57 im(:,:,1:3) = rgb2hsv(im_rgb); 63 im(:,:,4) = texture;58 %im(:,:,4) = texture; 64 59 65 60 … … 73 68 grass_s_hist = hist(reshape(clear_area(:,:,2), 1, []), hist_bins); 74 69 grass_v_hist = hist(reshape(clear_area(:,:,3), 1, []), hist_bins); 75 grass_t_hist = hist(reshape(clear_area(:,:,4), 1, []), hist_bins);70 %grass_t_hist = hist(reshape(clear_area(:,:,4), 1, []), hist_bins); 76 71 77 72 %hist(reshape(clear_area(:,:,1), 1, []), hist_bins); %displays histogram … … 82 77 s = ceil(im(:,:,2) * (hist_bins - 1)) + 1; 83 78 v = ceil(im(:,:,3) * (hist_bins - 1)) + 1; 84 t = ceil(im(:,:,4) * (hist_bins - 1)) + 1;79 %t = ceil(im(:,:,4) * (hist_bins - 1)) + 1; 85 80 86 81 % Make masks from the histograms. … … 94 89 %grass_t_mask(grass_t_hist < mean(grass_t_hist) * t_mean_factor) = 0; 95 90 91 fprintf('Generating mask\n'); 96 92 % Ungodly slow loop through the pixels 97 93 mask = zeros(rows, cols); … … 99 95 for c = 1:cols 100 96 if grass_h_mask(h(r,c)) && grass_s_mask(s(r,c)) && ... 101 grass_v_mask(v(r,c)) ...&& grass_t_mask(t(r,c))102 mask(r, c) = 1;97 grass_v_mask(v(r,c)) % && grass_t_mask(t(r,c)) 98 mask(r, c) = 1; 103 99 end 104 100 end 105 101 end 106 102 107 imwrite(mask, [fn '-mask-raw.png']); 103 if show_images 104 figure('Name','Raw mask'), imshow(mask) 105 else 106 imwrite(mask, [fn '-mask-raw.png']); 107 end 108 108 109 109 % Clean things up a bit … … 111 111 mask = imclose(mask, se); 112 112 113 imwrite(mask, [fn, '-mask-closed.png']); 114 115 tempMask=mask*-1+1; 116 bottomlist=bottomFind(tempMask); 117 imshow(tempMask); 113 if show_images 114 figure('Name','Cleaned up mask'), imshow(mask) 115 else 116 imwrite(mask, [fn '-mask-cleaned.png']); 117 end 118 119 fprintf('Locating obstacles\n'); 120 tempMask = mask * -1 + 1; 121 bottomlist = bottomFind(tempMask); 122 figure('Name','Obstacle points'), imshow(im_rgb); 118 123 hold on; 119 scatter(bottomlist(:,1),-bottomlist(:,2)); 120 print('-depsc', [fn '-obstacle-points.png']); 121 122 line_mask = texture; 124 scatter(bottomlist(:,1), -bottomlist(:,2)); 125 if ~show_images 126 print('-depsc', [fn '-obstacle-points.eps']); 127 end 128 129 line_mask = zeros(size(texture)); 123 130 threshold = .42; 124 131 line_mask(texture > threshold & mask == 0) = 1; 125 line_mask(texture <= threshold | mask ~= 0) = 0; 126 imwrite(line_mask, [fn '-line-mask.png']); 132 if show_images 133 figure('Name','Line mask'), imshow(line_mask) 134 else 135 imwrite(line_mask, [fn '-line-mask.png']); 136 end 127 137 128 138 % Display 129 figure(2); 130 imshow([double(im_rgb) / 255])%; bw2rgb(mask)]); 139 figure('Name','Clear area'), imshow([double(im_rgb) / 255])%; bw2rgb(mask)]); 131 140 132 141 % Draw a box over the "clear" area … … 137 146 line([left_x right_x right_x left_x left_x], ... 138 147 [top_y top_y bottom_y bottom_y top_y],'LineWidth',4,'Color','red'); 139 140 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%5 141 142 figure(3); 148 149 if ~show_images 150 print('-depsc', [fn '-clear-area.png']); 151 end 152 153 154 fprintf('Hough transform\n'); 143 155 144 156 [H,T,R] = hough(line_mask); 157 figure('Name','Hough peaks'); 145 158 imshow(H,[],'XData',T,'YData',R,'InitialMagnification','fit'); 146 159 xlabel('\theta'), ylabel('\rho'); … … 150 163 y = R(P(:,1)); 151 164 plot(x,y,'s','color','white'); 152 print('-depsc', [fn '-hough-peaks.eps']); 165 if ~show_images 166 print('-depsc', [fn '-hough-peaks.eps']); 167 end 153 168 154 169 lines = houghlines(line_mask,T,R,P,'FillGap',5,'MinLength',7); 155 figure, imshow(im_rgb), hold on 156 max_len = 0; 170 figure('Name','Hough lines'), imshow(im_rgb), hold on 157 171 for k = 1:length(lines) 158 172 xy = [lines(k).point1; lines(k).point2]; … … 162 176 plot(xy(1,1),xy(1,2),'x','LineWidth',8,'Color','yellow'); 163 177 plot(xy(2,1),xy(2,2),'x','LineWidth',8,'Color','red'); 164 165 % determine the endpoints of the longest line segment 166 len = norm(lines(k).point1 - lines(k).point2); 167 if ( len > max_len) 168 max_len = len; 169 xy_long = xy; 170 end 171 end 172 173 % highlight the longest line segment 174 plot(xy_long(:,1),xy_long(:,2),'LineWidth',8,'Color','cyan'); 175 print('-depsc', [fn '-hough-lines.eps']); 176 177 178 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 178 end 179 180 if ~show_points 181 print('-depsc', [fn '-hough-lines.eps']); 182 end 183 179 184 180 185 fprintf('Done\n'); -
branches/2010-image-rec/run.sh
r683 r687 12 12 fi 13 13 matlab $MFLAGS -r "hist_test('"$i"'); exit" 14 exit 14 15 done 15 16

