I want to use imagesc to crop and display a black and white (grayscale?) image. However, it keeps displaying the image in rgb, making it look like it came from an infra-red camera! Any tips for preserving the original colors?
You need to change the color map. After you run imagesc use colormap('Gray'). You can set default colormap to current colormap using colormap('default')
Related
I currently have a digital pathology image like this:
Firstly I turn the image into grayscale using the following codes:
img=imread('DigitalPathology8.png');
figure;
imshow(img)
hsv=rgb2hsv(img);
s=hsv(:,:,2);
And I got this grayscale image:
While I try to binarize this grayscale image using the following codes:
bw = imbinarize(s,'global');
figure
subplot(2,1,1)
imshow(s)
subplot(2,1,2)
imshow(bw)
I got the image like this:
What's wrong with my codes? When I applied the same algorithm to other images like this:
I could get the binarized image which only blue cells are white and other cells including backgrounds are black. So I also expect the same result after I applying the same codes to the first image I mentioned.
Could someone please help me out?
You should better use the rgb2gray()(look here) for your conversion:
grey=rgb2gray(img)
This should get you something like this:
Instead of global thresholding, i would recommend more sophisticated methods such as Otsu, which will get you much better results:
However, if you only want to extract the blue cells instead of a simple thresholded version of your image, you should use a totally different approach like MaxEntropy on the grayscale image. This will give you something like this:
and this
This tresholding method does not seem to be included in matlab, but a plugin can be found.
You could also try a total different approach to detect the blue dots by thresholding based on color similarity:
With this approach you would set each pixel to white which has a color distance to the blue color which is smaller than a given threshold. This should give you something like this (red markings represent the foreground of the image):
Reference color:
For this approach i took the RGB color (17.3,32.5,54.5) as reference color, my max distance was 210. If you have ImageJ, you can this approach interactivly, a while back i wrote a plugin for that.As you can see, this approach also detects wrong cells, which is caused by the high value for the distance and the choosen reference color. This errors may be minimized by selecting a more appropriate reference color and smaller distance values.
I need to detect an image is a color image or black&white image. But don't understand what will be the process or there have any function to detect it. If there have no function to detect it then what will be the process?
Image file has mode, which tells if it is RGB, grayscale or B&W.
I assume you know that and you are trying to examine a RGB image to see if it only has black / white color. In this case you can calculate the histogram of the image in all R/G/B channels, the black and white will have two sharp peaks in all three channels.
Please use a image editing software like GIMP and experiment.
I want to seprate RGB planes of a color image as three gray scale image in MATLAB. But they are colored. How can I do it? I use the below code:
red = I(:,:,1); % Red channel
green = I(:,:,2); % Green channel
Using image will show the matrix as an image with the default colour map of whatever version of MATLAB you are using. For version R2014b and higher, it will show this in the parula colour map and other versions show this in the jet colour map. If you wish to visualize this as a grayscale image, you must use colormap gray; after you call image.
However, if you have the Image Processing Toolbox, you can simply use imshow and single channel images default to showing the contents as grayscale.
I have original RGB image.
then, I convert it to gray scale.
then, I assign new threhold value into some pixel.
then, I need to convert the gray scale image from step#3 to RGB image.
I am trying on the step#4. Could you help to advise?
Check out rgb2hsv and hsv2rgb in matlab. Then threshold on the value matrix. This makes more sense to me.
Another possibility is to convert to grey scale but keep the original colour image. Then create a mask by thresholding the grey scale image and use that mask to discard the pixels above/below your threshold on the colour matrix.
I am on MAC OSX.
How to convert an gray scaled image to the RGB format.
Can i use the CIFilters for converting? Or any other way
And also i want to reverse the operation. i.e., convert the RGB format to Gray scaled format.
Regards,
Dhanaraj.
You can draw the grayscale image into an RGB-color context and export that image. Of course, the ability to draw a grayscale image into a non-grayscale context means you probably don't need to convert the image in the first place, since it will be done for you on-the-fly.
Core Image requires RGB images as input and produces them as output. I think it will convert a non-RGB image for you, so you could just use some simple filter in its identity configuration, but that's unnecessary.
What are you really trying to do that requires you to convert the image?