Greyscale colours

Still plodding along with my library to read DICOM files (medical images).

I have a two-dimensional array (rows x columns) of pixel data where each element in the array is a value between x and y (where x = black and y = white). Values between x and y are shades of grey.

I am trying to convert this array into a Picture object. I know I can set the individual colour of a pixel through the Picture.Graphics.Pixel method but what I can’t figure out is how to convert my values (of between 0-1) into grayscale Xojo Colors. Does that make sense??

what I can't figure out is how to convert my values (of between 0-1) into grayscale Xojo Colors. Does that make sense??

You need to translate those to values between 0 and 255
Simply multiply by 255

eg a value of 0 becomes 0 the rgb value of the Xojo pixel is rgb(0,0,0)

A value of 1 becomes 255 the rgb value is rgb(255,255,255)

Apply these to an rgbsurface rather than .graphics for speed.

And if 90% of the image is likely to be white, dont set the white pixels.


if newvalue < 255 then myrgbsurface.pixel(x,y) = rgb(newvalue,newvalue,newvalue) else //do nothing as it is already white end if

That’s set me off in the right direction. Thanks

On a related note, a lot of the files actually seem to have 4096 levels of grey (12 bits) - this is common for CT scans. Is there a way to scale this to RGB?

Hi Garry, you mean to convert that to 8 bit RGB images?
I can’t tell you about the fastest way of doing it in Xojo, but I can try to explain what you are dealing with and how you would convert it manually.

If your images are like mine, you have 12 bit data within a 16 bit file. Since RGB images have three 8 bit channels you need to convert those 12 bits to 8 bits (by dividing by 4 bits).

However, you may need to take into account where the actual data range (those 4096 levels of grey) are within your 16 bit range. In the case of the images I am working with (transmision electron microscopy, similar to CT scans) the actual data are not always in the same range within the 16 bits. So, you first must shift all the grey levels to asign a 0 value to the lowest grey level value present in your image, then divide by those 4 bits.

Would you mind posting a histogram of the grey levels of the image? You can do it using ImageJ, which if you don’t know about I think you should check it. ImageJ allows you to process images and sets of images using macros/scripts too, which may be an option in your case.


Ah, didn’t realise that.

I’ll posts a histogram as soon as I get s chance (on call tonight). Thanks Julen.