Question

So here are the details (I am using C# BTW):

I receive a 32bpp image (JPEG compressed) from a server. At some point, I would like to use the Palette property of a bitmap to color over-saturated pixels (brightness > 240) red. To do so, I need to get the image into an indexed format.

I have tried converting the image to a GIF, but I get quality loss. I have tried creating a new bitmap in an index format by these methods:

// causes a "Parameter not valid" error
Bitmap indexed = new Bitmap(orig.Width, orig.Height, PixelFormat.Indexed)

// no error, but the resulting image is black due to information loss I assume
Bitmap indexed = new Bitmap(orig.Width, orig.Height, PixelFormat.Format8bppIndexed)

I am at a loss now. The data in this image is changed constantly by the user, so I don't want to manually set pixels that have a brightness > 240 if I can avoid it. If I can set the palette once when the image is created, my work is done. If I am going about this the wrong way to begin with please let me know.

EDIT: Thanks guys, here is some more detail on what I am attempting to accomplish.

We are scanning a tissue slide at high resolution (pathology application). I write the interface to the actual scanner. We use a line-scan camera. To test the line rate of the camera, the user scans a very small portion and looks at the image.

The image is displayed next to a track bar. When the user moves the track bar (adjusting line rate), I change the overall intensity of the image in an attempt to model what it would look like at the new line rate. I do this using an ImageAttributes and ColorMatrix object currently.

When the user adjusts the track bar, I adjust the matrix. This does not give me per pixel information, but the performance is very nice. I could use LockBits and some unsafe code here, but I would rather not rewrite it if possible. When the new image is created, I would like for all pixels with a brightness value of > 240 to be colored red. I was thinking that defining a palette for the bitmap up front would be a clean way of doing this.

Was it helpful?

Solution 3

Thanks for the help everyone. It seems that this can be solved using the ImageAttributes class and simply setting a color remap table.

ColorMap[] maps = new ColorMap[someNum]
//  add mappings
imageAttrs.SetRemapTable(maps);

Thanks for the help again, at least I learned something.

OTHER TIPS

Going from 32bpp to 8bpp indexed will almost always result in quality loss, unless the original image has less than 256 colors total.

Can you create another image that is a overlay with the affected pixels red, then show both of those?

Since you are going for brightness > 240, you can convert the overlay to grayscale first, then to indexed to get the overbright pixels.

You don't specify what you are doing with it once you have tagged the offenders, so I don't know if that will work.

Sounds like something you could do easily with a pixel shader. Even very early shader models would support something as easy as this.

The question is however:

Can you include shader support in your application without too much hastle?

Do you know shader programming?

EDIT:

You probably don't have a 3D context where you can do stuff like this =/

I was mostly just airing my thoughts.

Manipulating the picture pixel by pixel should be doable in real-time with a single CPU shouldn't it?

If not, look into GPGPU programming and Open CL.

EDIT AGAIN:

If you gave some more details about what the app actually does we might help a bit more? For example, if you're making a web-app none of my tips would make sense.

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