Question

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#?

Was it helpful?

Solution 2

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 :)

OTHER TIPS

There are no unsigned chars in C#

Byte. Char in C/C++ is a byte in C#, and there are bytes in C# ;)

also the way he access the image data is completely different.

Hardly. ImageData is a bitmap of some type and he does simple bitmap stuff via array syntax. THis is doable in C# too - grab the bitmap or whatever interim form he uses and put it into a byte array. Now without understanding what he does that is a lost cause. I am also not sure I Woudl not blow that up into a DirectX surface and write a filter for that;)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top