Go Back   Velocity Reviews > Newsgroups > VHDL
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

VHDL - 3x3 sobel edge detection

 
Thread Tools Search this Thread
Old 06-12-2007, 07:49 PM   #1
Default 3x3 sobel edge detection


I'm working on sobel edge detection on an fpga using a 3x3 mask. To store the pixel values of the input image, I've decided to use an array. I wrote the code for just the array and some test code to see how it's working. The code worked, so I tried adding a "full" bit that would say when to stop loading the memory. For some reason, whenever I use the "full" bit and implement it to prevent the array from loading again once it's full, the array won't load at all and I get no output. The code is pretty simple and it seems like adding the full bit shouldn't be an issue. Does anyone have any suggestions on what I might be doing wrong?

And the code:

Library IEEE;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_misc.all;

entity sobel is
PORT ( input: IN integer:=0;
SW: IN integer:=0;
output: OUT integer:=0;
LEDR: OUT integer:=0;
LEDG: OUT std_logic_vector(8 DOWNTO 0);
CLOCK_50: IN std_logic);
end sobel;


architecture sobelizer of sobel is



constant num_cols: Natural:=640;
constant num_rows: Natural:=480;
constant edge: Natural:=0;
constant foreground: Natural:=255;
constant threshold: Natural:=68;
subtype pixel is integer;
signal full: std_logic:='0';

type memory_array is array (1 to 3, 1 to num_cols) of pixel;
type mask is array (1 to 3, 1 to 3) of pixel;
type next3 is array (1 to 3) of pixel;

begin
process

variable A : mask:=((0,0,0),(0,0,0),(0,0,0));
variable X1 : Natural:=1;
variable Y1 : Natural:=1;
variable Current_X: Integer:=1;
variable Current_Y: Integer:=1;
variable memory: memory_array;

begin

Wait Until CLOCK_50'EVENT and CLOCK_50='1';

if full='0' then

memory(X1,Y1):=input;
X1:=X1+1;
Current_X:=X1;
CUrrent_Y:=Y1

if X1=num_cols+1 then
X1:=1;
Y1:=Y1+1;
current_Y:=Y1;
end if;

if (current_X=num_cols) and (current_Y=num_rows) then
full<='1';
X1:=0;
Y1:=0;
end if;

elsif full='1' then
X1:=0;
Y1:=0;

end if;

end process;
end sobelizer;


dashdingo

Last edited by dashdingo : 06-15-2007 at 06:56 PM.
dashdingo is offline   Reply With Quote
Old 06-19-2007, 05:00 AM   #2
quantum_dot
Member
 
Join Date: Nov 2006
Posts: 32
Default
You have not defined parameters in sensitivity lists. signal "full" should be in sensitivity list. Or you can modify your process like :

process( CLOCK_50 )

variable A : mask:=((0,0,0),(0,0,0),(0,0,0));
variable X1 : Natural:=1;
variable Y1 : Natural:=1;
variable Current_X: Integer:=1;
variable Current_Y: Integer:=1;
variable memory: memory_array;

begin

if CLOCK_50'EVENT and CLOCK_50='1' then

if full='0' then

memory(X1,Y1):=input;
X1:=X1+1;
Current_X:=X1;
CUrrent_Y:=Y1

if X1=num_cols+1 then
X1:=1;
Y1:=Y1+1;
current_Y:=Y1;
end if;

if (current_X=num_cols) and (current_Y=num_rows) then
full<='1';
X1:=0;
Y1:=0;
end if;

elsif full='1' then
X1:=0;
Y1:=0;

end if;

end if;

end process;
end sobelizer;


quantum_dot
quantum_dot is offline   Reply With Quote
Old 06-26-2007, 09:44 PM   #3
dashdingo
Junior Member
 
Join Date: Jun 2007
Posts: 4
Default
Thank you for your help! I ended up changing the code around so the "full" issue could be worked around. I now have a working edge detection algorithm with a few issues that need to be worked out. I keep getting triples of the input image on the output. I'm thinking it's because I set a lower resolution for the output because the FPGA can't hold a full 640x3 array in addition to all the other code. Either that, or I'm having a timing issue.


dashdingo
dashdingo is offline   Reply With Quote
Old 09-26-2009, 06:57 PM   #4
minhhn0205
Junior Member
 
Join Date: Sep 2009
Posts: 1
Unhappy
I have 1 code about 8 mask sobel as follows. Please help me.
Thanks you very much!!!
Code:
#include "stdafx.h" #include <cv.h> #include <cxcore.h> #include <highgui.h> int sobel1[3][3]={{1,2,1},{0,0,0},{-1,-2,-1}}; int sobel2[3][3]={{2,1,0},{1,0,-1},{0,-1,-2}}; int sobel3[3][3]={{1,0,-1},{2,0,-2},{1,0,-1}}; int sobel4[3][3]={{0,-1,-2},{1,0,-1},{2,1,0}}; int sobel5[3][3]={{-1,-2,-1},{0,0,0},{1,2,1}}; int sobel6[3][3]={{-2,-1,0},{-1,0,1},{0,1,2}}; int sobel7[3][3]={{-1,0,1},{-2,0,2},{-1,0,1}}; int sobel8[3][3]={{0,1,2},{-1,0,1},{-2,-1,0}}; IplImage *img,*grayImg,*imgSobel1,*imgSobel2,*imgSobel3,*imgSobel4,*imgSobel5,*imgSobel6,*imgSobel7,*imgSobel8; void mask(IplImage *grayImg,IplImage *resultImg,int mask[3][3]){ int rows=grayImg->height; int cols=grayImg->width; int step=grayImg->widthStep; int dx[]={-1,-1,-1,0,0,0,1,1,1}; int dy[]={-1,0,1,-1,0,1,-1,0,1}; uchar * grayData=(uchar *)grayImg->imageData; uchar * resultData=(uchar *)resultImg->imageData; int i,j,k; // My question Is why i isn't equal 0 ~> equal 1 for(i=1;i<rows-1;i++) for(j=1;j<cols-1;j++){ resultData[i*step+j]=0; for(k=0;k<9;k++) // My question: You explain help me significance of line this code resultData[i*step+j]+=mask[1+dx[k]][1+dy[k]]*grayData[(i+dx[k])*step+j+dy[k]]; } } int _tmain(int argc, _TCHAR* argv[]) { img=cvLoadImage("../../test.jpg"); grayImg=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,1); imgSobel1=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,1); imgSobel2=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,1); imgSobel3=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,1); imgSobel4=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,1); imgSobel5=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,1); imgSobel6=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,1); imgSobel7=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,1); imgSobel8=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,1); cvCvtColor(img,grayImg,CV_BGR2GRAY); mask(grayImg,imgSobel1,sobel1); mask(grayImg,imgSobel2,sobel2); mask(grayImg,imgSobel3,sobel3); mask(grayImg,imgSobel4,sobel4); mask(grayImg,imgSobel5,sobel5); mask(grayImg,imgSobel6,sobel6); mask(grayImg,imgSobel7,sobel7); mask(grayImg,imgSobel8,sobel8); cvNamedWindow("Orginal Image",CV_WINDOW_AUTOSIZE); cvNamedWindow("Gray Image",CV_WINDOW_AUTOSIZE); cvNamedWindow("Sobel 1",CV_WINDOW_AUTOSIZE); cvNamedWindow("Sobel 2",CV_WINDOW_AUTOSIZE); cvNamedWindow("Sobel 3",CV_WINDOW_AUTOSIZE); cvNamedWindow("Sobel 4",CV_WINDOW_AUTOSIZE); cvNamedWindow("Sobel 5",CV_WINDOW_AUTOSIZE); cvNamedWindow("Sobel 6",CV_WINDOW_AUTOSIZE); cvNamedWindow("Sobel 7",CV_WINDOW_AUTOSIZE); cvNamedWindow("Sobel 8",CV_WINDOW_AUTOSIZE); cvShowImage("Orginal Image",img); cvShowImage("Gray Image",grayImg); cvShowImage("Sobel 1",imgSobel1); cvShowImage("Sobel 2",imgSobel2); cvShowImage("Sobel 3",imgSobel3); cvShowImage("Sobel 4",imgSobel4); cvShowImage("Sobel 5",imgSobel5); cvShowImage("Sobel 6",imgSobel6); cvShowImage("Sobel 7",imgSobel7); cvShowImage("Sobel 8",imgSobel8); cvWaitKey(0); cvDestroyAllWindows(); cvReleaseImage(&img); cvReleaseImage(&grayImg); cvReleaseImage(&imgSobel1); cvReleaseImage(&imgSobel2); cvReleaseImage(&imgSobel3); cvReleaseImage(&imgSobel4); cvReleaseImage(&imgSobel5); cvReleaseImage(&imgSobel6); cvReleaseImage(&imgSobel7); cvReleaseImage(&imgSobel8); return 0; }


minhhn0205

Last edited by minhhn0205 : 09-26-2009 at 07:00 PM.
minhhn0205 is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
i need Golf Ball motion detection simulator meao Software 1 10-11-2006 06:41 AM
KQEK.com DVD Reviews of Kolberg, River's Edge, Border Street & more! markh29@sympatico.ca DVD Video 0 07-16-2006 10:50 PM
DVD Verdict reviews: BAMBI: PLATINUM EDITION, BRIDGET JONES: THE EDGE OF REASON, and more! DVD Verdict DVD Video 0 03-28-2005 10:13 AM
Edge Enhancement Questions? Peter Mason DVD Video 29 11-09-2003 03:51 AM
Anyone Out There Like: The Cutting Edge ?? -- Or know anyting about it? Jeff DVD Video 0 09-12-2003 03:26 PM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46