- Joined
- Jun 1, 2009
- Messages
- 3
- Reaction score
- 0
Hi I'm new to VHDL, I'm thorough with all the basics of VHDL, now the task at hand I have is - to convert this piece of C code (Below) into a synthesisable VHDL code.
The C -code is, to binarize a given gray scale image, to do that I have to first find out the histogram (Easy and I could do it), second a threshold value, which I will use to classify the incoming pixel value whether it is above or below the threshold value and last send out the new pixel value.
For eg -
If threshold = 128
Incoming_pix = 56 Then outgoing_pix = 0
Incoming_pix = 200 Then outgoing_pix = 255
The thing which gives me creeps is the Division and Multiplication operations, Floating point arithmetic operations, Log function, how will I implement all that in VHDL?
Do I need to design a multiplier/divider, or should I have to ignore float and just go for whole numbers? How will I implement log function in VHDL, any alternative you guys can suggest?
Please give me some tips/pitfalls that I have to look out for, before I start designing this-
Is the problem as as tough as it is appearing?:-(
Thanks a lot!!!
***********C - Code************
NHIST = 256;
for (y = 0, n = 0; y < height; y++) {
for (x = 0; x < width; x++) {
iHist[imgIn[y][x]]++; // Histogram of the pixels
n++; // n = Number of pixels
}
/* compute probabilities */
for (i = 0; i < NHIST; i++)
prob = (double) iHist / (double) n;
/* find threshold */
for (i = 0, Hn = 0.0; i < NHIST; i++)
if (prob != 0.0)
Hn -= prob * log (prob);
for (i = 1, psiMax = 0.0; i < NHIST; i++) {
for (j = 0, Ps = Hs = 0.0; j < i; j++) {
Ps += prob[j];
if (prob[j] > 0.0)
Hs -= prob[j] * log (prob[j]);
}
if (Ps > 0.0 && Ps < 1.0)
psi = log (Ps - Ps * Ps) + Hs / Ps + (Hn - Hs) / (1.0 - Ps);
if (psi > psiMax) {
psiMax = psi;
thresh = i;
}
}
//******* End of C- code************
The C -code is, to binarize a given gray scale image, to do that I have to first find out the histogram (Easy and I could do it), second a threshold value, which I will use to classify the incoming pixel value whether it is above or below the threshold value and last send out the new pixel value.
For eg -
If threshold = 128
Incoming_pix = 56 Then outgoing_pix = 0
Incoming_pix = 200 Then outgoing_pix = 255
The thing which gives me creeps is the Division and Multiplication operations, Floating point arithmetic operations, Log function, how will I implement all that in VHDL?
Do I need to design a multiplier/divider, or should I have to ignore float and just go for whole numbers? How will I implement log function in VHDL, any alternative you guys can suggest?
Please give me some tips/pitfalls that I have to look out for, before I start designing this-
Is the problem as as tough as it is appearing?:-(
Thanks a lot!!!
***********C - Code************
NHIST = 256;
for (y = 0, n = 0; y < height; y++) {
for (x = 0; x < width; x++) {
iHist[imgIn[y][x]]++; // Histogram of the pixels
n++; // n = Number of pixels
}
/* compute probabilities */
for (i = 0; i < NHIST; i++)
prob = (double) iHist / (double) n;
/* find threshold */
for (i = 0, Hn = 0.0; i < NHIST; i++)
if (prob != 0.0)
Hn -= prob * log (prob);
for (i = 1, psiMax = 0.0; i < NHIST; i++) {
for (j = 0, Ps = Hs = 0.0; j < i; j++) {
Ps += prob[j];
if (prob[j] > 0.0)
Hs -= prob[j] * log (prob[j]);
}
if (Ps > 0.0 && Ps < 1.0)
psi = log (Ps - Ps * Ps) + Hs / Ps + (Hn - Hs) / (1.0 - Ps);
if (psi > psiMax) {
psiMax = psi;
thresh = i;
}
}
//******* End of C- code************