OpenCores
URL https://opencores.org/ocsvn/fpga-median/fpga-median/trunk

Subversion Repositories fpga-median

[/] [fpga-median/] [tags/] [fpga-filter-b1/] [software/] [generate_bram.m] - Blame information for rev 7

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 joaocarlos
% +----------------------------------------------------------------------------
2
% Universidade Federal da Bahia
3
% ------------------------------------------------------------------------------
4
% PROJECT: FPGA Median Filter
5
% ------------------------------------------------------------------------------
6
% FILE NAME            : generate_bram.m
7
% AUTHOR               : João Carlos Bittencourt
8
% AUTHOR'S E-MAIL      : joaocarlos@ieee.org
9
% -----------------------------------------------------------------------------
10
% RELEASE HISTORY
11
% VERSION  DATE        AUTHOR        DESCRIPTION
12
% 1.0      2013-09-02  laue.rami     initial version
13
% -----------------------------------------------------------------------------
14
% KEYWORDS: median, filter, image processing
15
% -----------------------------------------------------------------------------
16
% PURPOSE: Convert an image into a 3 block memory to be used in RTL.
17
% -----------------------------------------------------------------------------
18
 
19
clear
20
%read image
21
a = imread('images/image55.jpg');
22
%essa parte eh para deixar a imagem certinha 224x224
23
tmp = size(a);
24
lin = tmp(1,1);
25
col = tmp(1,2);
26
for i=1:lin-1
27
    for j=1:col-1
28
       a_mod(i,j) = a(i,j);
29
    end
30
end
31
%obtain image size
32
size_image = size(a_mod);
33
%create colum zeros
34
zero_coluna = zeros(size_image(1), 1);
35
%junta coluna de zeros na esquerda
36
left_edge = [zero_coluna a_mod];
37
%junta coluna de zeros na direita
38
both_edge = [left_edge zero_coluna];
39
%obtain image size
40
size_image = size(both_edge);
41
%create line zeros
42
zero_linha = zeros(1, size_image(2));
43
%junta linha de zero na parte de cima
44
up_edge = [zero_linha ; both_edge];
45
%junta linha de zero na parte de baixo
46
edge_image = [up_edge ; zero_linha];
47
%guarda o numero de linhas e o numero de colunas
48
temp = size(edge_image);
49
num_linhas = temp(1,1);
50
num_colunas = temp(1,2);
51
%abre arquivo para salvar a memoria
52
fileID_a = fopen('memA_hex.txt','w');
53
fileID_b = fopen('memB_hex.txt','w');
54
fileID_c = fopen('memC_hex.txt','w');
55
%transposta da imagem
56
new_image = edge_image.';
57
%converte para hexadecimal
58
image_hex = dec2hex(new_image);
59
%obtain o tamanho da imagem
60
aux = size(image_hex);
61
%obtain numero de pixels
62
num_pixels = aux(1,1);
63
 
64
image_conv = reshape(edge_image.',320,[]);
65
for i = 1 : size(image_conv)
66
    image_hex(i) = dec2hex(image_conv(i));
67
end
68
 
69
for i = 1 : size(image_conv)
70
    image_conv(i) = hex2dec(image_hex(i));
71
end
72
image = vec2mat(image_conv.',320);
73
 
74
imshow(image);
75
 
76
count = 1;
77
 
78
acc = num_linhas*3;
79
loops = num_pixels/acc;
80
 
81
for m=1:loops
82
 
83
    %para a memoria A - grava
84
    for ma=1:(num_linhas/4)
85
       for na=1:4
86
          fprintf(fileID_a,'%s',image_hex(count,:));
87
          count=count+1;
88
       end
89
       fprintf(fileID_a,'\n');
90
    end
91
 
92
    %para a memoria B - grava
93
    for ma=1:(num_linhas/4)
94
       for na=1:4
95
          fprintf(fileID_b,'%s',image_hex(count,:));
96
          count=count+1;
97
       end
98
       fprintf(fileID_b,'\n');
99
    end
100
 
101
    %para a memoria C - grava
102
    for ma=1:(num_linhas/4)
103
       for na=1:4
104
          fprintf(fileID_c,'%s',image_hex(count,:));
105
          count=count+1;
106
       end
107
       fprintf(fileID_c,'\n');
108
    end
109
end
110
 
111
fclose(fileID_a);
112
fclose(fileID_b);
113
fclose(fileID_c);
114
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.