algorithm - Supposed easy edge detection in MATLAB -


i have following image: , i'd detect contour of note intuitionally seen easy, when try it, isn't easy.

for quick prototyping started using matlab first (but later want in java i'd not use many special algorithms in matlab rather try use basic image proessing algorithms (prewitt / sobel / canny / adaptive thresholds / hough trafo) available in language (e.g. opencv etc)..

the easy code start (but thought should quite outside-edge looks strong compared inside ones):

i = double(rgb2gray(imread('img.jpg'))); bw = edge(i, 'canny'); imshow(bw) 

i thought matlab doing choice of threshold in canny filter when using automatical-mode. doesn't: http://i.imgur.com/lekpgso.png

when setting threshold scalar manually (to .4 e.g.) still way many gradients text inside , outside borders way incomplete/patchy: http://i.imgur.com/p68cviu.png

i tried using prewitt filter (in x , y direction):

i = double(rgb2gray(imread('img.jpg'))); f1 = double(fspecial('prewitt')); x = conv2(i, f); y = conv2(i, f'); bw = (x.^2+y.^2).^0.5; colormap(gray(256)) imagesc(bw); 

resulting in: http://i.imgur.com/jd9fqpn.png not well... looks better still outside patchy :(

any ideas how improve much? further i'd unwarp image later on rectangular shape. ideas on how it? hough transform wouldn't work on non-straight contour image above yields straight lines result...

thanks much!

edit: okay found out patchy-look comes matlab... when zooming in, much better , less patchy, see: http://i.imgur.com/urpd8me.png , imagine find contour shrinking outer contour because black in case (some sort of boundary box). don't want assume pictures not taken flashlight on, e.g.: http://i.imgur.com/nfqygma.jpg there noise in outer areas...

edit2: found algorithm detect corners of paper sheet in photo doesn't easy obviously. :) maybe you've got new ideas start with.

here prototype in c++:

#include <iostream> #include <vector> #include <stdio.h> #include <stdarg.h> #include "opencv2/opencv.hpp" #include "fstream" #include "iostream" using namespace std; using namespace cv; //----------------------------------------------------------------------------------------------------- //  //----------------------------------------------------------------------------------------------------- int main( int argc, char** argv ) {     namedwindow("img");     mat img=imread("test2.jpg",0);     cv::resize(img,img,size(img.cols/8,img.rows/8));     cv::threshold(img,img,100,255,cv::thresh_otsu);     cv::dilate(img,img,cv::mat::ones(3,3,cv_8uc1));     cv::erode(img,img,cv::mat::ones(23,23,cv_8uc1));     cv::resize(img,img,size(img.cols*8,img.rows*8));     imshow("img",img);     waitkey(0);     return 0; } 

it gives output image (after find contours).

enter image description here


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -