Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

deleted detectline folder in extract_digits

  • Loading branch information...
commit 835baa4379e069647fc47402bea6b2fb4e5b86f1 1 parent 662f897
Jennifer Guo authored
View
45 code/extract_digits/detectline/computegradients.m
@@ -1,45 +0,0 @@
-function [ xgradient_image, ygradient_image ] = computegradients( input_image )
-
- % Get the input image dimensions
- [height, width] = size(input_image);
-
- %{
- % Initialize gradient images to be all zeroes
- xgradient_image = zeros(height, width);
- ygradient_image = zeros(height, width);
- %}
-
-
- g_filter = fspecial('gaussian', 10, 1);
- d_filter_x = [-1,1];
- d_filter_y = [1 ; -1];
-
- %{
- xgradient_image = imfilter(gray_image, g_filter, 'conv');
- ygradient_image = imfilter(gray_image, g_filter, 'conv');
-
- xgradient_image = imfilter(xgradient_image, d_filter_x, 'conv');
- ygradient_image = imfilter(ygradient_image, d_filter_y, 'conv');
- %}
-
-
-
- filter_x = conv2(g_filter, d_filter_x, 'same');
- filter_y = conv2(g_filter, d_filter_y, 'same');
-
- xgradient_image = conv2(input_image, filter_x, 'same');
- ygradient_image = conv2(input_image, filter_y, 'same');
-
- %{
- xgradient_image = conv2(input_image, g_filter, 'same');
- ygradient_image = conv2(input_image, g_filter, 'same');
-
- xgradient_image = conv2((xgradient_image), d_filter_x, 'same');
- ygradient_image = conv2((ygradient_image), d_filter_y, 'same');
- %}
-
- %xgradient_image = ((xgradient_image + 255) / 510 * 255);
- %ygradient_image = ((ygradient_image + 255) / 510 * 255);
- % COMPUTE IMAGE GRADIENTS HERE
-
-end
View
70 code/extract_digits/detectline/detectedges.m
@@ -1,70 +0,0 @@
-function canny_image = detectedges( xgradient_image, ygradient_image )
-
- % Get the input image dimensions
- [height, width, ~] = size(xgradient_image);
-
-
- % Initialize output image to be all zeroes
- canny_image = zeros(height, width);
-
-
- magnitude = sqrt(xgradient_image .* xgradient_image + ygradient_image .* ygradient_image);
- direction = atan(ygradient_image ./ xgradient_image);
-
-
- supress_result = magnitude;
-
- for H = 2:1:height-1
- for W = 2:1:width-1
- if(direction(H,W)>=-(pi/8) && direction(H,W)<(pi/8))
- if(magnitude(H,W)<magnitude(H,W+1) || magnitude(H,W)<magnitude(H,W-1))
- supress_result(H,W) = 0;
- end
- elseif(direction(H,W)>=(pi/8) && direction(H,W)<(3*pi/8))
- if(magnitude(H,W)<magnitude(H-1,W+1) || magnitude(H,W)<magnitude(H+1,W-1))
- supress_result(H,W) = 0;
- end
- elseif(direction(H,W)>=-(3*pi/8)&& direction(H,W)<-(pi/8))
- if(magnitude(H,W)<magnitude(H-1,W-1) || magnitude(H,W)<magnitude(H+1,W+1))
- supress_result(H,W) = 0;
- end
- else
- if(magnitude(H,W)<magnitude(H-1,W) || magnitude(H,W)<magnitude(H+1,W))
- supress_result(H,W) = 0;
- end
-
- end
-
- end
- end
-
- for h=1:height-1:height
- for w=1:width-1:width
- supress_result(h,w) = 0;
- end
- end
-
-
- %{
- tHi = 0.08;
- tLo = 0.01;
- highmask = supress_result>tHi;
- lowmask = bwlabel(~(supress_result<tLo));
- final = ismember(lowmask,unique(lowmask(highmask)));
- canny_image = final .* magnitude;
- %}
-
-
- %imshow(uint8(magnitude));
- T_h = 0.08;
- T_l = 0.01;
- strong = (supress_result) > T_h;
- [weakr, weakc] = find((supress_result)>T_l);
- bw = bwselect(strong, weakc, weakr, 8);
- %canny_image = supress_result;
- %imshow(uint8(supress_result))
- canny_image = bw .* magnitude;
-
- % IMPLEMENT THE CANNY EDGE DETECTION ALGORITHM HERE
-
-end
View
107 code/extract_digits/detectline/predictlines.m
@@ -1,107 +0,0 @@
-function output_image = predictlines( canny_image, hough_transform, xgradient_image, ygradient_image, alpha, beta, gamma )
-
- % Get the input image dimensions
- [height, width, ~] = size(canny_image);
-
- % Initialize output image to be all zeroes
- output_image = zeros(height, width);
-
- [hough_height, hough_width] = size(hough_transform);
-
- theta = atan(ygradient_image ./ xgradient_image);
-
-
- for h=1:1:height
- y = -(h-height/2);
- for w=1:1:width
- x = w-width/2;
- if(canny_image(h,w)~=0)
- maximum = 0;
- for a=1:1:180
- d = -x*cos(degtorad(a)) - y*sin(degtorad(a));
- angle = a;
- if(d<=0)
- d = abs(d);
- angle = mod(angle+180,360);
- end
- ix1 = floor(d);
- ix2 = ceil(d);
- iy = angle;
- dx = d-ix1;
- weight1 = (1.0-dx);
- weight2 = dx;
-
- if(ix1==0)
- ix1 = hough_height;
- end
- if(ix2==0)
- ix2 = hough_height;
- end
- if(iy==0)
- iy = hough_width;
- end
-
- image = (canny_image(h,w)^alpha * (hough_transform(ix1,iy)*weight1+hough_transform(ix2,iy)*weight2)^beta * cos(theta(h,w)-degtorad(angle))^gamma);
- if(image>maximum)
- maximum = image;
- end
- end
- output_image(h,w) = maximum;
- end
- end
- end
-
-
-
- for h=1:height-1:height
- for w = 1:width-1:width
- output_image(h,w) = 0;
- end
- end
- output_image = output_image + 0.001;
- output_image = output_image / max(max(output_image)) +1 ;
- output_image = log(output_image);
- output_image = output_image+exp(1);
- output_image = output_image/exp(1);
- output_image = output_image / max(max(output_image));
- output_image(output_image <= 0.7985) = 0;
- output_image = output_image * 0.8;
-
-
-
- %{
- positive_list = output_image(output_image > 0);
- minimum = prctile(positive_list, 0) * 0.2;
- maximum = prctile(positive_list, 95) * 1.25;
- prctile(positive_list, 100);
- output_image( output_image > 0 & output_image < maximum ) = ...
- (output_image(output_image > 0 & output_image < maximum) - minimum) ./ (maximum - minimum);
- output_image( output_image >= maximum ) = 1;
- %}
-
- %{
-
- disp(max(max(output_image)));
- disp(min(min(output_image)));
-
- %}
-
- %{
-
- max_value = max(max(output_image));
- output_image = output_image / max_value;
-
- positive_list = output_image(output_image > 0);
-
- minimum = prctile(positive_list, 0) * 15;
- maximum = prctile(positive_list, 95) * 0.5;
- prctile(positive_list, 100);
- output_image( output_image > 0 & output_image < maximum ) = ...
- (output_image(output_image > 0 & output_image < maximum) - minimum) ./ (maximum - minimum);
- output_image( output_image >= maximum ) = 1;
- %}
- %disp(output_image)
-
- % COMBINE THE CANNY EDGES AND HOUGH TRANFORM INTO THE FINAL LINE PREDICTION HERE
-
-end
View
202 code/extract_digits/detectline/runme.m
@@ -1,202 +0,0 @@
-function [] = runme (force_overwrite)
- % By default we do not overwrite results
- if (nargin < 1)
- force_overwrite = false;
- end
-
- close all
-
- % Get list of all filenames in input directory
- filenames = dir('../input');
-
- % Keep record of the evaluation results for each input image
- %scores = [];
-
- % Process all filenames in input directory
- for i = 1:size(filenames)
- filename = filenames(i).name;
-
- % Check if filename is an image
- if (~isempty(strfind(filename, '.jpg')))
-
- % Determine filenames
- basename = strrep(filename, '.jpg', '');
- input_filename = strcat('../input/', basename, '.jpg');
- %canny_filename = strcat('../canny/', basename, '.jpg');
- %hough_filename = strcat('../hough/', basename, '.jpg');
- %stronglines_filename = strcat('../stronglines/', basename, '.jpg');
- output_filename = strcat('../output/', basename, '.jpg');
- %overlay_filename = strcat('../overlay/', basename, '.jpg');
- %groundtruth_filename = strcat('../groundtruth/', basename, '.jpg');
-
- % Create output image, if it does not already exist
- if (force_overwrite || ~exist(output_filename, 'file'))
- disp(['Creating ' output_filename]);
-
- % Read the input image
- input_image = imread(input_filename);
- if (size(input_image, 3) == 3)
- input_image = rgb2gray(input_image);
- end
- input_image = im2double(input_image);
-
- % Begin timer
- tic
-
- % Compute gradients
- [xgradient_image, ygradient_image] = computegradients ( input_image );
-
- % Detect Canny edges
- canny_image = detectedges ( xgradient_image, ygradient_image );
-
- % Compute Hough transform
- hough_transform = votelines ( canny_image, xgradient_image, ygradient_image );
-
- % Combine Canny and Hough into final output
- output_image = predictlines( canny_image, hough_transform, xgradient_image, ygradient_image, 1.0, 1.0, 2.0 );
-
-
-
- % End timer
- toc
-
- % Evaluate the output image by computing the correlation with the groundtruth image
- %{
- score = 0;
- if (exist(groundtruth_filename, 'file'))
- groundtruth_image = imread(groundtruth_filename);
- groundtruth_image = im2double(groundtruth_image);
- score = evaluate(output_image, groundtruth_image);
- disp(score)
- end
- scores = [scores; score];
- %}
-
- % Write the computed images
- %imwrite(visualnormalize(canny_image), canny_filename);
- %imwrite(visualnormalize(hough_transform), hough_filename);
- imwrite(output_image, output_filename);
- %imwrite(visualnormalize(output_image), output_filename);
-
- % Write an image that shows the strong lines (without scaling by the Canny edges or dot products)
- %stronglines_image = predictlines(canny_image, hough_transform, xgradient_image, ygradient_image, 0.0, 1.0, 0.0);
- %imwrite(visualnormalize(stronglines_image), stronglines_filename);
-
- %imwrite(stronglines_image, stronglines_filename);
-
- else
-
- % Read the previously computed output image
- output_image = im2double(imread(output_filename));
-
- % Evaluate the result by computing the correlation with the groundtruth image
-
- %{
- score = 0;
- if (exist(groundtruth_filename, 'file'))
- groundtruth_image = imread(groundtruth_filename);
- groundtruth_image = im2double(groundtruth_image);
- score = evaluate(output_image, groundtruth_image);
- end
- scores = [scores; score];
- %}
- end
-
- % Create overlay image, if it does not already exist
-
- %{
- if (~exist(overlay_filename, 'file'))
- disp(['Creating ' overlay_filename]);
-
- % Read the input and output images
- input_image = imread(input_filename);
- input_image = im2double(input_image);
- output_image = imread(output_filename);
- output_image = im2double(output_image);
-
- % Create the overlay image
- overlay_image = createoverlay(input_image, output_image);
-
- % Write the overlay image
- if (exist(groundtruth_filename, 'file'))
- % Add the score into the corner of the overlay image
- h = figure('Visible', 'off');
- hold on
- imshow(overlay_image, 'Border', 'tight');
- text(10, 10, num2str(score(end)),'color', [0 1 0], 'FontSize', 20);
- print(h, '-djpeg', overlay_filename);
- hold off
- close(h);
- else
- imwrite(overlay_image, overlay_filename);
- end
- end
- %}
-
- end
- end
-
- %Save the scores
- %save('score', 'score');
-
- %Plot the scores
- %figure;
- %plot(1:1:size(score, 1), score, '.-');
-
-end
-
-
-
-
-function overlay_image = createoverlay( image1, image2 )
- if ( size( image1, 3 ) == 1 )
- image1 = gray2rgb( image1 );
- end
- if ( size( image2, 3 ) == 1 )
- image2 = gray2red( image2 );
- end
- overlay_image = ( image1 + 10*image2 ) / 5;
-end
-
-
-
-function color_image = gray2rgb( image )
- im = zeros(size(image,1),size(image,2),3);
- im(:,:,1) = image;
- im(:,:,2) = image;
- im(:,:,3) = image;
- color_image = im;
-end
-
-
-
-function color_image = gray2red( image )
- im = zeros(size(image,1),size(image,2),3);
- im(:,:,1) = image;
- color_image = im;
-end
-
-
-
-function score = evaluate( prediction, groundtruth )
- if (size(prediction) ~= size(groundtruth))
- disp('Error: size of the output image should be consistent with the input image.');
- else
- score = corr2(prediction, groundtruth);
- end
-end
-
-
-
-function normalized_image = visualnormalize( image )
- [height, width] = size(image);
- normalized_image = zeros(height, width);
- positive_list = image(image > 0);
- minimum = prctile(positive_list, 0) * 0.7;
- maximum = prctile(positive_list, 95) * 1.25;
- prctile(positive_list, 100);
- normalized_image( image > 0 & image < maximum ) = ...
- (image(image > 0 & image < maximum) - minimum) ./ (maximum - minimum);
- normalized_image( image >= maximum ) = 1;
-end
-
View
80 code/extract_digits/detectline/votelines.m
@@ -1,80 +0,0 @@
-function hough_transform = votelines( canny_image, xgradient_image, ygradient_image )
-
- % Get the input image dimensions
- [height, width, ~] = size(canny_image);
-
- % Initialize output image to be all zeroes
- hough_transform = zeros(round((height^2 + width^2)^0.5/2 + 1), 360);
-
- [hough_height, hough_width] = size(hough_transform);
-
-% theta = atand(ygradient_image ./ xgradient_image);
- %theta = flipud(theta);
- theta = atan(ygradient_image ./ xgradient_image);
- theta1 = theta;
- theta = radtodeg(theta);
-
-
- for h=1:1:height
- y = -(h-height/2);
- for w=1:1:width
- x = w-width/2;
- if(canny_image(h,w)~=0)
- d = -x*cos(theta1(h,w)) - y*sin(theta1(h,w));
- a = theta(h,w);
- if(theta(h,w)<0)
- a = theta(h,w) + 360;
- end
-
- if(d<0)
- d = abs(d);
- a = mod(a + 180,360);
-
- end
-
-
- ix1 = floor(d);
- iy1 = floor(a);
- ix2 = ceil(d);
- iy2 = ceil(a);
- dx = d-ix1;
- dy = a-iy1;
-
- if(ix1==0)
- ix1 = hough_height;
- end
- if(iy1==0)
- iy1 = hough_width;
- end
- if(ix2==0)
- ix2 = hough_height;
- end
- if(iy2==0)
- iy2 = hough_width;
- end
-
- weight1 = (1.0-dx)*(1.0-dy);
- weight2 = (1.0-dx)*dy;
- weight3 = dx*(1.0-dy);
- weight4 = dx*dy;
- hough_transform(ix1,iy1) = hough_transform(ix1,iy1) + canny_image(h,w)*weight1;
- hough_transform(ix1,iy2) = hough_transform(ix1,iy2) + canny_image(h,w)*weight2;
- hough_transform(ix2,iy1) = hough_transform(ix2,iy1) + canny_image(h,w)*weight3;
- hough_transform(ix2,iy2) = hough_transform(ix2,iy2) + canny_image(h,w)*weight4;
-
-
- end
- end
- end
-
- %imshow(hough_transform)
-
- %figure, imshow(hough_transform)
-
-
-
-
-
- % IMPLEMENT THE HOUGH TRANFORM VOTING ALGORITHM HERE
-
-end
Please sign in to comment.
Something went wrong with that request. Please try again.