I'm trying to implement an retinex filter following the one posted here. At the beginning he defines:
#define pc(image, x, y, c) image->imageData[(image->widthStep * y) + (image->nChannels * x) + c]
and when doing the gaussian convolution he is using it as:
v1 += kernel[k] * (unsigned char)pc(temp, i, source, 0);
and later:
pc(img, i, j, 0) = (char)int2smallint(v1);
I'm not able to translate this to C#, neither do I understand what he's doing exactly. There are no unsigned chars in C# and also the way he access the image data is completely different. So, what is the best way to implement this in C#?
ok i solved it. This:
v1 += kernel[k] * (unsigned char)pc(temp, i, source, 0);
is translated to:
IntPtr ptr = img.ImageData;
v1 += kernel[k] * Marshal.ReadByte(ptr, (i * img.WidthStep) + (source * img.NChannels) + 0);
Marshal is the answer :)