-1

I have a code to save the image from a sensor of x-ray. The image is grayscaled. But I need some modifications on this image. Where the image are black, I need it to be white.

See that original image.

enter image description here

This is another image, but the details is white here, is that what I need.

enter image description here

  • What is your question? What does the code actually do now? How is that different from what you want? Please read the [help] pages about how to write a good question that will be on-topic for this site. Please [edit] the question to add the missing information. – AdrianHHH Sep 15 '21 at 13:07
  • I need to change the color, to invert black and white. The first image are from the sensor I'm using and for the SDK I have. The second are from other sensor, but you can se that the black and withe are inverted. Seems to me that the background of image 1 are black and for the image 2 are white. – MatheusCandido Sep 15 '21 at 13:18
  • I don't think that just replace are the best choice. I'm using a 16 bit of grayscale, so i'ts not just black or white, I need something like "reverse polarity". – MatheusCandido Sep 15 '21 at 15:24

1 Answers1

0

If you are using a 8bit bitmap image it is a simple operation of doing

var v = byte.MaxValue - myBitmap.GetPixel(x, y).R;
myBitmap.SetPixel(x,y, Color.FromArgb(v, v, v)

Or see fast work with bitmaps to access the pixel values directly.

JonasH
  • 28,608
  • 2
  • 10
  • 23
  • I'm using a 16bit bitmap image – MatheusCandido Sep 15 '21 at 14:11
  • The principle is the same, `var newValue = ushort.MaxValue - oldValue`. But if you are not using the built in image classes, and do not show any code, it is difficult to be more specific. – JonasH Sep 15 '21 at 14:26
  • The problem is that I also don't have access to the code that generates the image. I just have the SDK to acquire and connect with the sensor. So I'm searching for some method to 'clarify' the grayscale – MatheusCandido Sep 15 '21 at 14:33
  • @Matheus Candido you do not need access to the code for generating the image. you **do** need access to the actual image data, or an existing method in the SDK to do whatever you need to do. – JonasH Sep 15 '21 at 14:37
  • I have acess to the data of the image. Are a array of short, I convert to bitmap then save the file. I will try the link you send. – MatheusCandido Sep 15 '21 at 14:41
  • @Matheus Candido if you have an array of shorts, just write a loop and do `myArray[i] = short.MaxValue - myArray[i]`. Note that you probably need to select a smaller range of values if you want to convert it to a 8bit image for saving or displaying, sometimes called windowing. – JonasH Sep 15 '21 at 14:46