Hello,

I am trying to compute the log transformation of an image(very easy... I know). But I am not getting the right result and I really don't know what I am doing wrong. I know the image provided is in the range of 0 and 1.5x10^6. But when I save the pixel values of this image to a text file, the maximum value that I observe is 20. I think this is preventing my calculations, but I don't know how to fix it? *really frustrated because I have tried everything I can think of.

Thanks for your help in advance

Please see code:

```
void logTransform()
{
IplImage *imgforLog;
imgforLog = cvLoadImage("l.BMP",1);
int heightLog, widthLog;
uchar *dataLog;
heightLog = imgforLog->height;
widthLog = imgforLog->width;
dataLog = (uchar*) imgforLog->imageData;
IplImage *logtr;
logtr = cvCreateImage( cvGetSize(imgforLog), IPL_DEPTH_8U, 1 );
uchar *log_data;
log_data = (uchar*)logtr->imageData;
int logt;
float r;
long int answer;
cvSaveImage("Saved/inputlog.png", imgforLog);
//note: when c_fm, c_fs, min_log, max_log was set to double it gave weird result (image)
int c_fm, c_fs, min_log, max_log;
min_log = log_data[0];
max_log = log_data[0];
cout << min_log << ":" << max_log << endl;
for ( int a = 0; a < sizeof(imgforLog); a++)
{
for (int i = 0; i < heightLog; i++) {
for (int j = 0; j < widthLog; j++) {
logt = 0;
r = (dataLog[((widthLog * i) + j)]);
logt = (1 *log10(1+r));
if(min_log < logt)
{
a++;
}
else if (min_log > logt)
{
min_log = logt;
}
}}
}
for ( int a = 0; a < sizeof(imgforLog); a++)
{
for (int i = 0; i < heightLog; i++) {
for (int j = 0; j < widthLog; j++) {
logt = 0;
r = (dataLog[((widthLog * i) + j)]);
logt = (1 *log10(1+r));
if(max_log > logt)
{
a++;
}
else if (max_log < logt)
{
max_log = logt;
}
}}
}
cout << min_log << ":" << max_log << endl;
for (int i = 0; i < heightLog; i++)
{
for (int j = 0; j < widthLog; j++)
{
logt = 0;
r = (dataLog[((widthLog * i) + j)]);
logt = (1 *log10(1+r));
c_fm = logt - min_log;
c_fs = (R_MAX * (c_fm/max_log));
log_data[((widthLog * i) + j)] = c_fs;
}
}
cvSaveImage("Saved/Log.png", logtr);
cvReleaseImage(&img);
cvReleaseImage(&image);
cvReleaseImage(&imgforLog);
cvReleaseImage(&logtr);
}
```