img_gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY) img_gray = np.asarray(img_gray) hfilt = Gauss2D((5, 5), sigma) # Q3.1 Convolution # you can change the parameters for Gauss2D Im1 = myImageFilter(img_gray, hfilt) # plt.imshow(Im1,cmap="gray");plt.show() Im1X = myImageFilterX(img_gray, hfilt) # cv2.normalize(Im1X,Im1X, 0, 1, cv2.NORM_MINMAX) plt.imshow(Im1X, cmap="gray") plt.show() # Q3.3 ImEdge, Io, Ix, Iy = myEdgeFilter(img_gray, sigma) # plt.imshow(ImEdge,cmap="gray");plt.show() Thresh = 50 #0.2 # change it as needed ThrImEdge = 1.0 * (ImEdge > Thresh) # plt.imshow(ThrImEdge,cmap="gray");plt.show() ''' print(ImEdge[:50, :20]) print(img_rgb.dtype) print(ThrImEdge.dtype) exit() ''' # Q3.4 H, rhoScale, thetaScale = myHoughTransform(ThrImEdge, rhoRes, thetaRes) # plt.imshow(H);plt.show()
for file in os.listdir(datadir): if file.endswith(".jpg"): imglist.append(file) imglist.sort() for i in range(len(imglist)): # read in images fname = os.path.join(datadir, imglist[i]) img = sp.ndimage.imread(fname) if img.ndim == 3: img = rgb2gray(img) img = np.float64(img) / 255.0 # actual Hough line code function calls Im = myEdgeFilter(img, sigma) # H, rhoScale, thetaScale = myHoughTransform(Im, threshold, rhoRes, thetaRes) # rhos, thetas = myHoughLines(H, nLines) # thresh_img = Im > threshold # lines = houghlines(thresh_img, 180 * (thetaScale / math.pi), rhoScale, # rhos, thetas, fillgap=5, minlength=20) # everything below here just saves the outputs to files filename_w_ext = os.path.basename(imglist[i]) filename, file_extension = os.path.splitext(filename_w_ext) fname = os.path.join(resultsdir, filename + '_01edge.png') temp = np.uint8(255.0 * np.sqrt(Im / np.max(Im))) sp.misc.imsave(fname, temp) fname = os.path.join(resultsdir, filename + '_02threshold.png') temp = np.uint8(255.0 * (Im > threshold)) sp.misc.imsave(fname, temp)