Rose-Hulman Robotics Team

Changeset 653

Show
Ignore:
Timestamp:
02/05/10 12:26:46 (2 years ago)
Author:
mosttw
Message:

Made sobel.py output sobels of HSV channels individually. Added texture to hist_test.m, though it doesn't really help.

Location:
branches/2010-image-rec
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • branches/2010-image-rec/hist_test.m

    r647 r653  
    99fn = 'images/elphel/cam-000094.jpeg'; 
    1010fn = 'images/elphel/cam-000081.jpeg'; 
     11 
     12fprintf('Running on %s... ', fn); 
    1113 
    1214% Number of bins in the histogram. 
     
    2123s_mean_factor = 0.2; % Seems to most effect obstacle detection 
    2224v_mean_factor = 0.1; % Obstacles and lines 
     25t_mean_factor = 0.1; 
     26texture_band = 2; 
    2327 
    24 im = imread(fn); 
    25 im = imresize(im, 0.25); 
    26 im = rgb2hsv(im); 
     28im_rgb = imread(fn); 
     29im_rgb = imresize(im_rgb, 0.25); 
     30rows = size(im_rgb, 1); 
     31cols = size(im_rgb, 2); 
    2732 
    28 rows = size(im, 1); 
    29 cols = size(im, 2); 
     33im = zeros(rows, cols, 4); 
     34im(:,:,1:3) = rgb2hsv(im_rgb); 
     35fsobel = fspecial('sobel'); 
     36hedges = filter2(fsobel , im(:,:,texture_band)); 
     37vedges = filter2(fsobel', im(:,:,texture_band)); 
     38edges = sqrt(hedges .^ 2 + vedges .^ 2); 
     39texture = filter2(fspecial('average', 10), edges); 
     40texture = filter2(fspecial('average', 10), texture); 
     41texture = filter2(fspecial('average', 10), texture); 
     42texture = filter2(fspecial('average', 10), texture); 
     43texture = filter2(fspecial('average', 10), texture); 
     44texture = filter2(fspecial('average', 10), texture); 
     45texture = filter2(fspecial('average', 10), texture); 
     46texture = filter2(fspecial('average', 10), texture); 
     47texture(texture > 1) = 1; 
    3048 
     49figure(1); 
     50imshow([edges; texture]); 
     51 
     52im(:,:,4) = texture; 
    3153 
    3254% Area at the bottom of the image assumed to be grass, clear of obstacles 
     
    3961grass_s_hist = hist(reshape(clear_area(:,:,2), 1, []), hist_bins); 
    4062grass_v_hist = hist(reshape(clear_area(:,:,3), 1, []), hist_bins); 
     63grass_t_hist = hist(reshape(clear_area(:,:,4), 1, []), hist_bins); 
    4164 
    4265% Make matrices with values that are indices into the histograms 
     
    4467s = ceil(im(:,:,2) * (hist_bins - 1)) + 1; 
    4568v = ceil(im(:,:,3) * (hist_bins - 1)) + 1; 
     69t = ceil(im(:,:,4) * (hist_bins - 1)) + 1; 
    4670 
    4771% Make masks from the histograms. 
     
    5276grass_v_mask = grass_v_hist; 
    5377grass_v_mask(grass_v_hist < mean(grass_v_hist) * v_mean_factor) = 0; 
     78grass_t_mask = grass_t_hist; 
     79grass_t_mask(grass_t_hist < mean(grass_t_hist) * t_mean_factor) = 0; 
    5480 
    5581% Ungodly slow loop through the pixels 
     
    5783for r = 1:rows 
    5884    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)) 
    6087            mask(r,c) = 1; 
    6188        end 
     
    6491 
    6592% 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); 
    6895 
    6996% Display 
    70 imshow([im; bw2rgb(mask)]); 
     97figure(2); 
     98imshow([double(im_rgb) / 255; bw2rgb(mask)]); 
    7199 
    72100% Draw a box over the "clear" area 
  • branches/2010-image-rec/sobel.py

    r640 r653  
    55 
    66fn = sys.argv[1] 
    7 try: 
    8         use_hsv = sys.argv[2] == 'hsv' 
    9 except IndexError: 
    10         use_hsv = False 
    117 
    128im = 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 
     9hsv = cv.CreateImage((im.width, im.height), cv.IPL_DEPTH_8U, 3) 
     10cv.CvtColor(im, hsv, cv.CV_BGR2HSV) 
     11im = hsv 
    1712 
    18 print "sobelizing" 
     13print "sobelizing", 
    1914sobel = 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) 
     19cv.Sobel(im, sobel, 1, 1, 3) 
     20 
    2121#cv.ShowImage('window', sobel) 
    2222#cv.WaitKey() 
    2323sobel_img = cv.CreateImage((im.width, im.height), cv.IPL_DEPTH_8U, 3) 
    2424cv.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) 
     25sobel_h = cv.CreateImage((im.width, im.height), cv.IPL_DEPTH_8U, 1) 
     26sobel_s = cv.CreateImage((im.width, im.height), cv.IPL_DEPTH_8U, 1) 
     27sobel_v = cv.CreateImage((im.width, im.height), cv.IPL_DEPTH_8U, 1) 
     28cv.Split(sobel_img, sobel_h, sobel_s, sobel_v, None) 
     29cv.SaveImage(fn + '-sobel-h.png', sobel_h) 
     30cv.SaveImage(fn + '-sobel-s.png', sobel_s) 
     31cv.SaveImage(fn + '-sobel-v.png', sobel_v) 
     32print "wrote %s-sobel-[hsv].png" % fn 
    3133sys.exit(0) 
    3234