how to display dicom image in matlab always with black background ? - matlab

I have a problem with some dicom images. Maybe they have a different image range.
Generally it display as normal with black background but sometimes it display with white background. I have a question : what can I change it ? I would like to display images always with black background.
I would appreciate for any help/advice. I don't know what I should change ?
Agata

Please check the value of Photometric Interpretation (0028, 0004). This specifies the intended interpretation of the image pixel data. If the value is “MONOCHROME1” than the minimum sample value of pixel data is intended to be displayed as white (after any Modality LUT transformation) and maximum pixel value as black (inverted grayscale image)

Related

The image size is changed when the image is too big

I am using an image with size 4000*3000 pixels. When I show this image through the imshow function, the program shows:
Image is too big to fit on screen : displaying at 67%.
After that, when I want to find size of the image with function size(), the number of column is always multiplied by 3 from the original image. For example, when my image is 563*1000, this function show me 563*3000.
Could anyone tell me how to fix this problem?

Image resize issue

This appears to be a trivial problem but the result is strange, totally lost where I am going wrong. There is an input RGB image which needs to be converted to gray scale and sized to 1000 x 1000 pixels. This is how I have done
img=imread('flowers.jpg');
flowers_gray=rgb2gray(img);
flowers_resize=imresize(flowers_gray,[1000 1000]);
but strangely the output image is not of 1000 by 1000 pixels. Moreover, matlab did not save the image (tried using SaveAs option and the File --->Export Setup) gray scale mode
and also the size was incorrect since when I opened the saved image by
img1=imread('flowers_resize.jpg')
s=size(img1)
it gave
s=586 665 3
And the image flowers_resize.jpg is saved with a white border surrounding it in the image folder. So, I went to Paint toolbox to select the image A1 and manually deleted the surrounding background and resized the image.But alas, it saved the image with 3 color channels and not in gray scale mode although the size was correct! Can somebody please point out the correct way of resizing to 1000 by 1000 pixels and saving in gray scale mode without the white border surrounding the saved output file? Thank you.
When you use the image export processing, you are saving the entire figure including the space around the figure (white space).
Instead, use the imwrite command. In your case:
imwrite(A1,'flowers_resize.jpg','jpg');

iPhone iOS how to instantiate a black and white CGColorSpaceRef?

I'm working with this excellent example of converting an image to grayscale: Convert Image to B&W problem CGContext - iPhone Dev
However, for my purposes, I would like to have only pure black and pure white left in the image.
It appears that to do so, I need to pass a black and white color space to the recolor method using a call:
CGColorSpaceRef colorSpace = CGColorSpaceCreateWithName(/*black and white name*/);
However, I was unable to find the proper iOS color space names. What I found was from Mac, and the "color space names" referenced from the iOS docs does not point anywhere.
How can I properly create a black and white CGColorSpaceRef?
Thank you!
I am not familiar with a black and white only color space but what you can do is calculate the total average RGB value from all the pixels (lets call it totalAvg) and use it as a threshold. Meaning for each pixel if its rgb average is greater than the calculated totalAvg than set it to pure white, otherwise set it to pure black.
I agree it is a bit of more work but thats whay I can think of unless you find the colorspace you are looking for.
You might try creating a gray color space, then creating an indexed color space with two colors (black and white, obviously) and using that.

How to convert a black and white photo that was originally colored, back to its original color?

I've converted a colored photo to black and white, and bolded the edges. Now i need to convert it back to its original color with the bolded edges. Is there any function in matlab which allows me to do so?
Once you remove the colour from an image, there is no possible way to automatically put it back. You're basically reducing a set of 16,777,216 colours to a set of 256 - on average each shade of grey has 65,536 equivalent colours, and without the original image there's no way to guess which it could be.
Now, if you were to take the bolded lines from your black-and-white image and paint them on top of the original coloured image, that might end up producing what you're looking for.
If what you are trying to do is to use some filter over the B/W image and then use that with the original color. I suggest you convert your image to a color space with Lightness channel that suits your needs (for example L*a*b* if you need the ligtness to be uniformly distributed regarding human recognition of differences) and apply your filter only over the Lightness channel.

Histogram of image

I have 2 images that look nearly identical. The histogram for one (256 bins) has intensities distributed pretty evenly throughout. The other has intensities at the lowest and highest bin. Why would this be? Then wouldnt it appear binary (thats not the case)?
Think about it this way: Imagine you are taking a histogram of two grayscale images with each pixel represented by a color value 0-255. One image contains pixels that all have gray levels of 128. The second image contains a "checkerboard" pattern (pixels alternate between 0 and 255). If you step back far enough that you no longer see individual pixels, they will appear identical to the naked eye. Your brain "averages" the alternating black and white pixels into a field of gray.
This is what your images are doing. The first image has colors distributed evenly throughout the range and the second image has concentrations of specific colors, but if you calculate an average color for the image (and also for sub-sections within the image) you should see similar values for both.
Never trust in your eyes! They will always lie to you.
Consider this silly example that can be illustrative here. An X-Ray 'photo' is nothing more than black and white dots. But as they are small and mixed along the image, your eyes see different shades of gray.
The same can happen in a digital image, where, although the pixels may have the same size, then can be black and white and 'distributed' in the image in such a way that you see it as having more graylevels. This is called halftone.
Without seeing the images it's hard to say, but it sounds like the second may be slightly clipped.
The difference also could just be a slight difference in contrast in the images that's no visible to the naked eye.