URL
https://opencores.org/ocsvn/fpga-median/fpga-median/trunk
Subversion Repositories fpga-median
Compare Revisions
- This comparison shows the changes necessary to convert path
/fpga-median
- from Rev 6 to Rev 7
- ↔ Reverse comparison
Rev 6 → Rev 7
/tags/fpga-filter-b1/software/median_ref.m
0,0 → 1,65
% +---------------------------------------------------------------------------- |
% Universidade Federal da Bahia |
% ------------------------------------------------------------------------------ |
% PROJECT: FPGA Median Filter |
% ------------------------------------------------------------------------------ |
% FILE NAME : median_ref.m |
% AUTHOR : João Carlos Bittencourt |
% AUTHOR'S E-MAIL : joaocarlos@ieee.org |
% ----------------------------------------------------------------------------- |
% RELEASE HISTORY |
% VERSION DATE AUTHOR DESCRIPTION |
% 1.0 2013-08-27 joao.nunes initial version |
% ----------------------------------------------------------------------------- |
% KEYWORDS: median, filter, image processing |
% ----------------------------------------------------------------------------- |
% PURPOSE: Reference model for Median Filter. |
% ----------------------------------------------------------------------------- |
|
% This is only a simple verification reference model based on default Median Filter |
|
% Clear environment |
clc |
clear |
% Set-up vectors |
% I have set the vector to size 12 in order to perform a basic testbench. |
% result = zeros(227,227); |
img_ref = imread('images/image22.jpg'); |
|
img_ref = rgb2gray(img_ref); |
[width, height] = size(img_ref); |
% Add one column with zeros for pipelining verification purpose. |
% The hardware assumes that, in the first round in a row, previous values are zeros. |
img = zeros(width+1,width+1); |
for i = 1 : height, |
img(i,2:width+1) = img_ref(i, 1:width); |
end |
|
|
% Default Median Algorithm |
window_width = 3; |
window_height = 3; |
edgex = floor(window_width/2); |
edgey = floor(window_height/2); |
tic |
for x = edgex : width - edgex, |
for y = edgey : height - edgey, |
temp = zeros(edgex,edgey); |
for fx = 1 : window_width, |
for fy = 1 : window_height, |
temp(fx,fy) = img(x + fx - edgex, y + fy - edgey); |
end |
end |
temp = reshape(temp.',1,[]); |
srt = sort(temp); % remove comma to view step by step outputs |
result(x,y) = srt(5); |
end |
end |
toc |
wtime = toc |
fprintf ( 1, ' MY_PROGRAM took %f seconds to run.\n', wtime ); |
|
%result |
imshow(mat2gray(result)); |
imwrite(mat2gray(result), 'images/image22_median.jpg', 'jpg'); |
|
/tags/fpga-filter-b1/software/generate_bram.m
0,0 → 1,114
% +---------------------------------------------------------------------------- |
% Universidade Federal da Bahia |
% ------------------------------------------------------------------------------ |
% PROJECT: FPGA Median Filter |
% ------------------------------------------------------------------------------ |
% FILE NAME : generate_bram.m |
% AUTHOR : João Carlos Bittencourt |
% AUTHOR'S E-MAIL : joaocarlos@ieee.org |
% ----------------------------------------------------------------------------- |
% RELEASE HISTORY |
% VERSION DATE AUTHOR DESCRIPTION |
% 1.0 2013-09-02 laue.rami initial version |
% ----------------------------------------------------------------------------- |
% KEYWORDS: median, filter, image processing |
% ----------------------------------------------------------------------------- |
% PURPOSE: Convert an image into a 3 block memory to be used in RTL. |
% ----------------------------------------------------------------------------- |
|
clear |
%read image |
a = imread('images/image55.jpg'); |
%essa parte eh para deixar a imagem certinha 224x224 |
tmp = size(a); |
lin = tmp(1,1); |
col = tmp(1,2); |
for i=1:lin-1 |
for j=1:col-1 |
a_mod(i,j) = a(i,j); |
end |
end |
%obtain image size |
size_image = size(a_mod); |
%create colum zeros |
zero_coluna = zeros(size_image(1), 1); |
%junta coluna de zeros na esquerda |
left_edge = [zero_coluna a_mod]; |
%junta coluna de zeros na direita |
both_edge = [left_edge zero_coluna]; |
%obtain image size |
size_image = size(both_edge); |
%create line zeros |
zero_linha = zeros(1, size_image(2)); |
%junta linha de zero na parte de cima |
up_edge = [zero_linha ; both_edge]; |
%junta linha de zero na parte de baixo |
edge_image = [up_edge ; zero_linha]; |
%guarda o numero de linhas e o numero de colunas |
temp = size(edge_image); |
num_linhas = temp(1,1); |
num_colunas = temp(1,2); |
%abre arquivo para salvar a memoria |
fileID_a = fopen('memA_hex.txt','w'); |
fileID_b = fopen('memB_hex.txt','w'); |
fileID_c = fopen('memC_hex.txt','w'); |
%transposta da imagem |
new_image = edge_image.'; |
%converte para hexadecimal |
image_hex = dec2hex(new_image); |
%obtain o tamanho da imagem |
aux = size(image_hex); |
%obtain numero de pixels |
num_pixels = aux(1,1); |
|
image_conv = reshape(edge_image.',320,[]); |
for i = 1 : size(image_conv) |
image_hex(i) = dec2hex(image_conv(i)); |
end |
|
for i = 1 : size(image_conv) |
image_conv(i) = hex2dec(image_hex(i)); |
end |
image = vec2mat(image_conv.',320); |
|
imshow(image); |
|
count = 1; |
|
acc = num_linhas*3; |
loops = num_pixels/acc; |
|
for m=1:loops |
|
%para a memoria A - grava |
for ma=1:(num_linhas/4) |
for na=1:4 |
fprintf(fileID_a,'%s',image_hex(count,:)); |
count=count+1; |
end |
fprintf(fileID_a,'\n'); |
end |
|
%para a memoria B - grava |
for ma=1:(num_linhas/4) |
for na=1:4 |
fprintf(fileID_b,'%s',image_hex(count,:)); |
count=count+1; |
end |
fprintf(fileID_b,'\n'); |
end |
|
%para a memoria C - grava |
for ma=1:(num_linhas/4) |
for na=1:4 |
fprintf(fileID_c,'%s',image_hex(count,:)); |
count=count+1; |
end |
fprintf(fileID_c,'\n'); |
end |
end |
|
fclose(fileID_a); |
fclose(fileID_b); |
fclose(fileID_c); |
|
/tags/fpga-filter-b1/software/median_return.m
0,0 → 1,32
clc |
clear |
|
id = fopen('image.hex', 'r'); |
image_c = fscanf(id, '%d'); |
|
%image = vec2mat(image_c, 866); |
%image = reshape(image_c,598,866); |
% image = reshape(image_c.',598,[]); |
|
image = zeros(227,227); |
k = 1; |
for i = 1 : 227 |
z = 0; |
for j = 1 : 227 |
image(i,j) = hex2dec(image_c(k)); |
k = k + 1; |
end |
end |
|
% for i = 1 : 510 |
% for j = 1 : 510 |
% if(image(i,j) == 255) |
% image(i,j) = 0; |
% else |
% image(i,j) = 1; |
% end |
% end |
% end |
|
imshow(image); |
% imwrite(image, 'return.jpg', 'jpg'); |
/tags/fpga-filter-b1/software/convert_rtl.m
0,0 → 1,50
% +---------------------------------------------------------------------------- |
% Universidade Federal da Bahia |
% ------------------------------------------------------------------------------ |
% PROJECT: FPGA Median Filter |
% ------------------------------------------------------------------------------ |
% FILE NAME : convert_rtl.m |
% AUTHOR : João Carlos Bittencourt |
% AUTHOR'S E-MAIL : joaocarlos@ieee.org |
% ----------------------------------------------------------------------------- |
% RELEASE HISTORY |
% VERSION DATE AUTHOR DESCRIPTION |
% 1.0 2013-08-27 joao.nunes initial version |
% 2.0 2013-09-03 laue.rami fix problem with vec2mat fucntion usage |
% ----------------------------------------------------------------------------- |
% KEYWORDS: median, filter, image processing |
% ----------------------------------------------------------------------------- |
% PURPOSE: Convert a RTL memory in an image matrix |
% ----------------------------------------------------------------------------- |
|
clc |
clear |
|
id = fopen('image.hex','r'); |
|
for i=1:102400 % vector width |
image_rtl(i,1) = fscanf(id, '%c', 1); |
image_rtl(i,2) = fscanf(id, '%c', 1); |
lixo(1) = fscanf(id, '%c', 1); |
end |
|
|
% for i=1:51984 |
% image(i) = hex2dec(image_rtl(i,:)); |
% end |
var = hex2dec(image_rtl); |
|
count=1; |
for i=1:320 % height |
for j=1:320 % width |
foto(i,j)= var(count); |
count=count+1; |
end |
end |
foto = foto; |
% image = vec2mat(image,228); |
a = mat2gray(foto); |
imshow(mat2gray(foto)); |
imwrite(a, 'image_transform.jpg', 'jpeg'); |
|
fclose(id); |