Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > 3x3 sobel edge detection

Reply
Thread Tools

3x3 sobel edge detection

 
 
dashdingo dashdingo is offline
Junior Member
Join Date: Jun 2007
Posts: 4
 
      06-12-2007
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;
 

Last edited by dashdingo; 06-15-2007 at 05:56 PM..
Reply With Quote
 
 
 
 
quantum_dot quantum_dot is offline
Member
Join Date: Nov 2006
Posts: 32
 
      06-19-2007
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;
 
Reply With Quote
 
 
 
 
dashdingo dashdingo is offline
Junior Member
Join Date: Jun 2007
Posts: 4
 
      06-26-2007
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.
 
Reply With Quote
 
minhhn0205 minhhn0205 is offline
Junior Member
Join Date: Sep 2009
Posts: 1
 
      09-26-2009
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;
}
 

Last edited by minhhn0205; 09-26-2009 at 06:00 PM..
Reply With Quote
 
 
 
Reply

Thread Tools

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sobel Edge detectors deepsri.88 Java 0 11-07-2010 07:29 AM
3x3 Array of int, changing one value affects others Williams Williams Ruby 2 09-28-2010 09:05 AM
edge detection using sobel kumar9422 VHDL 0 05-29-2010 10:44 AM
6x6 kernel from a 3x3 nia_hicham VHDL 0 05-14-2007 03:22 PM
Boost.graph - changing edge end-points or copying an edge Ferdi Smit C++ 0 10-10-2005 04:30 PM



Advertisments
 



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 47 48 49 50 51 52 53 54 55 56 57