How can I convert my Matlab code into Hdl code?
5 views (last 30 days)
Show older comments
Here is my code of matlab, which I want to convert in vhdl. I tried Hdl coder app of Matlab-R2013a but there are some problem in converting this code into vhdl.Can anyone help me out here. I need it for my project.
I = imread('C:\Users\gaurishankar\Desktop\pr1.jpg'); %read the image
A = rgb2gray(I); %convert RGB to graylevel image
figure, imshow(I); title('original image') %show image
b = ones(9,9) / 64; %smoothing filter
B = imfilter(A,b);
figure, imshow(B); title('spatial filter')
c = fspecial('average',[3 3]); %averaging filter
C = imfilter(B,c);
figure,imshow(C), title('Frequency filter')
level = graythresh(C);%set threshold value between 0 and 1
D = im2bw(C,0.900); %convert to binary image
figure,imshow(D),title('Threshold segmented image');
e = strel('disk',20);%morphological operation using disk structuring element
E = imerode(D,e); %erosion process
figure,imshow(E),title('erosion image')
f = strel('disk',20); %se size 15
F = imdilate(E,f); %dilation process
figure,imshow(F),title('dilation image')
hy = fspecial('sobel'); %edge detection
hx = hy';
Iy = imfilter(double(F), hy, 'replicate');
Ix = imfilter(double(F), hx, 'replicate');
gradmag = sqrt(Ix.^2 + Iy.^2);
g = gradmag - min(gradmag(:)); %set gradient edge
g = g / max(g(:));
th = graythresh(g); %# Otsu's method.
a = imhmax(g,th/2); %# Conservatively remove local maxima.
th = graythresh(a);
b1 = a > th/4; %# Conservative global threshold.
c1 = imclose(b1,ones(6));
g2 = imimposemin(g, ~ imdilate( bwperim(a), ones(3) ));
figure,imshow(g2),title('Edge Detection');
DE = bwselect(F);
figure, imshow(DE); title('Selected Image')
see = strel('disk',20);
dee = imdilate(DE,see);
figure, imshow(dee); title('Original Size')
figure, imshow(I); title('Location on Original Image');
Z=bwboundaries(dee);
text(10,10,strcat('\color{red}Objects Found:',num2str(length(Z))))
hold on
for k = 1:length(Z)
boundary = Z{k};
plot(boundary(:,2), boundary(:,1), 'm', 'LineWidth', 2.0)
end
0 Comments
Answers (2)
Walter Roberson
on 24 Apr 2014
VHDL cannot do file-I/O (e.g., imread), and cannot do graphics (e.g., figure, imshow, text, plot)
0 Comments
Tim McBrayer
on 24 Apr 2014
The tool your are looking for is HDL Coder. HDL Coder can convert your floating-point untimed MATLAB code in to clocked, fixed-point HDL code.
As Walter implies, you will need to clearly understand what parts of your code is the testbench (the code that provides stimulus do your design) and what part is the actual design you wish to generate HDL for. File and graphical options, it should be obvious, cannot have HDL code generated for them. The list of MATLAB functions that are supported are available in this MATLAB Answer.
I suggest you start with the examples provided with the product so that you can understand the capabilities of HDL Coder. The style of code shown in your example will need some work in order to make it ready for HDL code generation.
0 Comments
See Also
Categories
Find more on HDL Coder in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!