Forum Discussion
Taking image as input
Hello friends.....i am trying to do image processing using DE2 board in verilog hdl and i had written the code...but i got stucked at taking image as input and to load it into the memory on the board.....
Gupta12 Replies
- Altera_Forum
Honored Contributor
You should post more information in order to allow the community helping you. What do you mean by "got stucked"? Where exactly is the problem?
- Altera_Forum
Honored Contributor
What is your video capture device? it's a terasic camera?
- Altera_Forum
Honored Contributor
i am not capturing any image for my project and i am just taking already captured image...i have an idea of taking image by LUT register or by using SD ram...do u have any idea regarding these methods??...anyways thanks for ur reply and interest
- Altera_Forum
Honored Contributor
i got stucked means...i dont have any knowledge regarding image processing using FPGA...i wrote code to process image after taking it as input....i dont know how to connect image inout to my code
- Altera_Forum
Honored Contributor
Try with a .mif file related to a lpm_rom megafunction.
In this file you should include the image contents, organized, i.e, by rows. This matlab function takes a matlab vector var and creates a .mif file of depth cells and width bits each one. function miffile(filename,var,width,depth) fh=fopen(strcat(filename,'.mif'),'w+'); fprintf(fh,'WIDTH=%d;\r\n',width); fprintf(fh,'DEPTH=%d;\r\n',depth); fprintf(fh,'ADDRESS_RADIX=DEC;\r\n'); fprintf(fh,'DATA_RADIX=DEC;\r\n'); fprintf(fh,'CONTENT BEGIN\r\n'); for k=1:length(var) fprintf(fh,strcat(num2str(k-1),':',num2str(var(k)),';\n')); end fprintf(fh,'END;\r\n'); fclose(fh); Matlab stores the image as a matrix, you should resize it as a vector. in order to read the ROM include two counters, index_column and index_row. index_rom=index_row*(columns_per_row) + index_column - Altera_Forum
Honored Contributor
I agree with parrado, and another way could be to instantiate an ALTSYNCRAM block and use it as a ROM (it is a possibility offered by the MegaWizard). The ROM should be initialized by a MIF file and the ROM cells should be read sequentially by building a simple external verilog code that generates the addresses that are sent to the read_addr port of the ALTSYNCRAM block.
It is a simple job, just try it out and tell us if you encounter problems. - Altera_Forum
Honored Contributor
Thanks for your replies...i will check them and tell
- Altera_Forum
Honored Contributor
--- Quote Start --- Try with a .mif file related to a lpm_rom megafunction. In this file you should include the image contents, organized, i.e, by rows. This matlab function takes a matlab vector var and creates a .mif file of depth cells and width bits each one. function miffile(filename,var,width,depth) fh=fopen(strcat(filename,'.mif'),'w+'); fprintf(fh,'WIDTH=%d;\r\n',width); fprintf(fh,'DEPTH=%d;\r\n',depth); fprintf(fh,'ADDRESS_RADIX=DEC;\r\n'); fprintf(fh,'DATA_RADIX=DEC;\r\n'); fprintf(fh,'CONTENT BEGIN\r\n'); for k=1:length(var) fprintf(fh,strcat(num2str(k-1),':',num2str(var(k)),';\n')); end fprintf(fh,'END;\r\n'); fclose(fh); Matlab stores the image as a matrix, you should resize it as a vector. in order to read the ROM include two counters, index_column and index_row. index_rom=index_row*(columns_per_row) + index_column --- Quote End --- In the above matlab code what do you mean by filename in the arguments.....should i need to give image name...if so i gave the filename as avergra2.bmp (function miffile(avergra2,var,width,depth)) can you also explain what is the purpose of index_rom (the last command) - Altera_Forum
Honored Contributor
You must read the image:
I=imread('your_image-bmp'); Resize the image in order to access it from a plain rom Ir=reshape(I',prod(size(I)),1); Now you can generate your mif file: miffile('your_image.mif',Ir,8,length(Ir)) Each pixel is coded using 8 bits. (gray scale images). If you are going to process true color images, you should instance 3 memories for each color plane. This .mif file can be used in an altsyncram megafunction instantiated in ROM mode. The index_rom is the address of the altsyncram. This logic must be implemented in your hardware. - Altera_Forum
Honored Contributor
yeah...i did all this things and i got the result later...i am sorry that i did not updated it here.....
i took image of size 64*64 and i got result a vector of length 4096..... now i am trying to implment altsyncram...i will write the code and if i get any errors i will paste it here..... anyways thank you very much for your help......i promise that it was really very helpful