Changeset 653
- Timestamp:
- 02/05/10 12:26:46 (2 years ago)
- Location:
- branches/2010-image-rec
- Files:
-
- 2 modified
-
hist_test.m (modified) (7 diffs)
-
sobel.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/2010-image-rec/hist_test.m
r647 r653 9 9 fn = 'images/elphel/cam-000094.jpeg'; 10 10 fn = 'images/elphel/cam-000081.jpeg'; 11 12 fprintf('Running on %s... ', fn); 11 13 12 14 % Number of bins in the histogram. … … 21 23 s_mean_factor = 0.2; % Seems to most effect obstacle detection 22 24 v_mean_factor = 0.1; % Obstacles and lines 25 t_mean_factor = 0.1; 26 texture_band = 2; 23 27 24 im = imread(fn); 25 im = imresize(im, 0.25); 26 im = rgb2hsv(im); 28 im_rgb = imread(fn); 29 im_rgb = imresize(im_rgb, 0.25); 30 rows = size(im_rgb, 1); 31 cols = size(im_rgb, 2); 27 32 28 rows = size(im, 1); 29 cols = size(im, 2); 33 im = zeros(rows, cols, 4); 34 im(:,:,1:3) = rgb2hsv(im_rgb); 35 fsobel = fspecial('sobel'); 36 hedges = filter2(fsobel , im(:,:,texture_band)); 37 vedges = filter2(fsobel', im(:,:,texture_band)); 38 edges = sqrt(hedges .^ 2 + vedges .^ 2); 39 texture = filter2(fspecial('average', 10), edges); 40 texture = filter2(fspecial('average', 10), texture); 41 texture = filter2(fspecial('average', 10), texture); 42 texture = filter2(fspecial('average', 10), texture); 43 texture = filter2(fspecial('average', 10), texture); 44 texture = filter2(fspecial('average', 10), texture); 45 texture = filter2(fspecial('average', 10), texture); 46 texture = filter2(fspecial('average', 10), texture); 47 texture(texture > 1) = 1; 30 48 49 figure(1); 50 imshow([edges; texture]); 51 52 im(:,:,4) = texture; 31 53 32 54 % Area at the bottom of the image assumed to be grass, clear of obstacles … … 39 61 grass_s_hist = hist(reshape(clear_area(:,:,2), 1, []), hist_bins); 40 62 grass_v_hist = hist(reshape(clear_area(:,:,3), 1, []), hist_bins); 63 grass_t_hist = hist(reshape(clear_area(:,:,4), 1, []), hist_bins); 41 64 42 65 % Make matrices with values that are indices into the histograms … … 44 67 s = ceil(im(:,:,2) * (hist_bins - 1)) + 1; 45 68 v = ceil(im(:,:,3) * (hist_bins - 1)) + 1; 69 t = ceil(im(:,:,4) * (hist_bins - 1)) + 1; 46 70 47 71 % Make masks from the histograms. … … 52 76 grass_v_mask = grass_v_hist; 53 77 grass_v_mask(grass_v_hist < mean(grass_v_hist) * v_mean_factor) = 0; 78 grass_t_mask = grass_t_hist; 79 grass_t_mask(grass_t_hist < mean(grass_t_hist) * t_mean_factor) = 0; 54 80 55 81 % Ungodly slow loop through the pixels … … 57 83 for r = 1:rows 58 84 for c = 1:cols 59 if grass_h_mask(h(r,c)) && grass_s_mask(s(r,c)) && grass_v_mask(v(r,c)) 85 if grass_h_mask(h(r,c)) && grass_s_mask(s(r,c)) && ... 86 grass_v_mask(v(r,c)) && grass_t_mask(t(r,c)) 60 87 mask(r,c) = 1; 61 88 end … … 64 91 65 92 % Clean things up a bit 66 se = strel('square', 4);67 mask = imclose(mask, se);93 % se = strel('square', 4); 94 % mask = imclose(mask, se); 68 95 69 96 % Display 70 imshow([im; bw2rgb(mask)]); 97 figure(2); 98 imshow([double(im_rgb) / 255; bw2rgb(mask)]); 71 99 72 100 % Draw a box over the "clear" area -
branches/2010-image-rec/sobel.py
r640 r653 5 5 6 6 fn = sys.argv[1] 7 try:8 use_hsv = sys.argv[2] == 'hsv'9 except IndexError:10 use_hsv = False11 7 12 8 im = cv.LoadImage(fn) 13 if use_hsv: 14 hsv = cv.CreateImage((im.width, im.height), cv.IPL_DEPTH_8U, 3) 15 cv.CvtColor(im, hsv, cv.CV_BGR2HSV) 16 im = hsv 9 hsv = cv.CreateImage((im.width, im.height), cv.IPL_DEPTH_8U, 3) 10 cv.CvtColor(im, hsv, cv.CV_BGR2HSV) 11 im = hsv 17 12 18 print "sobelizing" 13 print "sobelizing", 19 14 sobel = cv.CreateMat(im.height, im.width, cv.CV_32FC3) 20 cv.Sobel(im, sobel, 1, 1, 5) 15 #sobel_x = cv.CreateMat(im.height, im.width, cv.CV_32FC3) 16 #sobel_y = cv.CreateMat(im.height, im.width, cv.CV_32FC3) 17 #cv.Sobel(im, sobel_x, 1, 0, 3) 18 #cv.Sobel(im, sobel_y, 0, 1, 3) 19 cv.Sobel(im, sobel, 1, 1, 3) 20 21 21 #cv.ShowImage('window', sobel) 22 22 #cv.WaitKey() 23 23 sobel_img = cv.CreateImage((im.width, im.height), cv.IPL_DEPTH_8U, 3) 24 24 cv.ConvertScale(sobel, sobel_img, 8.0) 25 if use_hsv: 26 sobel_fn = fn + '-hsv-sobel.png' 27 else: 28 sobel_fn = fn + '-sobel.png' 29 30 cv.SaveImage(sobel_fn, sobel_img) 25 sobel_h = cv.CreateImage((im.width, im.height), cv.IPL_DEPTH_8U, 1) 26 sobel_s = cv.CreateImage((im.width, im.height), cv.IPL_DEPTH_8U, 1) 27 sobel_v = cv.CreateImage((im.width, im.height), cv.IPL_DEPTH_8U, 1) 28 cv.Split(sobel_img, sobel_h, sobel_s, sobel_v, None) 29 cv.SaveImage(fn + '-sobel-h.png', sobel_h) 30 cv.SaveImage(fn + '-sobel-s.png', sobel_s) 31 cv.SaveImage(fn + '-sobel-v.png', sobel_v) 32 print "wrote %s-sobel-[hsv].png" % fn 31 33 sys.exit(0) 32 34

