I have a grayscale image in Matlab that I want to convert to an RGB image. To plot it I can simply do
imagesc(img)
colormap jet
or replace colormap jet with any other colormap. How would I get the actual array of RGB values that would give the equivalent image if I were to do image(img)?
Related
The documentation of histeq in Matlab says:
[___,T] = histeq(___) also returns the transformation T that maps the gray component of the input grayscale image or colormap to the gray component of the output grayscale image or colormap.
How do I apply this transformation T to another image (not the image that I put into histeq)?
The input to histeq was a greyscale image, the output T is a 1×256 double vector.
The following line from histeq.m might be the solution:
builtin("_grayxformmex", new_image, T);
I would like to map HSV values to color names in MATLAB. I have converted RGB to HSV and thresholded the values using a series of if statements in order to determine the color . However I would instead like to map the values to defined color names. Is this possible in MATLAB?
If you're working with an mxnx3 (i.e. 2D with 3 channels) RGB image im, then typically the red channel is im(:,:,1), green is im(:,:,2), and blue is im(:,:,3). So if you want the RGB values at some point (x, y), then you can get the vector by im(x,y,:).
If you just want to convert HSV values to RGB, then you can use the function hsv2rgb.
We want to plot in Matlab using mesh function the FFT2 of an image (we have applied fftshift, abs, and log).
So how do we do that?
imageB=imread('pic2', 'jpg');
figure, imshow(imageB)
fftB=fft2(double(imageB));
F1=fftshift(fftB);
F2=abs(F1);
F3=log(F2+1);
mesh(F3)
We want a 3-D plot of the FFT.
An option using surf:
imageB=rgb2gray(imread('http://upload.wikimedia.org/wikipedia/commons/d/db/Patern_test.jpg'));
Note that the original image is a RGB image, thus the FFT will also be a 3-channel array. Either convert to grayscale or access one channel with F1(:,:,1)
fftB=fft2(double(imageB));
F1=log(abs(fftshift(fftB)));
surf(F1), shading flat;
Result:
I have a similar question than the one in this post.
I have a grayscale image and I plot points on it. Fro plotting the points I use colormap('jet') but as I want the image to be grayscale, after plotting the points I reset the colormap, colormap('gray').
But I want to show a colorbar! And the colorbar is plotted in grayscale, not 'jet'.
How can I do that?
EDIT:
I want a Colorbar showing the color of the points!
You should convert your image to RGB by putting the same data into R-, G-, and B-channels (this will be grayscale RGB image). Colormap in MatLab is not applied to RGB images, only to indexed ones. Then plot your points over the image with colormap you like.
As discussed here, there's a few ways:
If you have the image processing toolbox, use subimage to create an independent image with a separate colormap. Then plot the image, your points, and join them into one using linkaxes.
Use freezeColors from the file exchange (or multiple colormaps, which I haven't ever tested personally). This is a very easy way to create a larger colormap, and automatically selecting the right portion of the colormap for display of images and colorbars.
As answered by anandr, convert your greyscale image to RGB; Matlab doesn't use colormaps on RGB images, which leaves you freedom to plot your points and show their colorbar independent of the image.
Example code for (3):
I = imread('cameraman.tif');
imshow(cat(3,I,I,I))
hold on
x = #() round(size(I,1) * rand(50,1));
y = #() round(size(I,2) * rand(50,1));
plot(x(), y(), 'r.')
plot(x(), y(), 'g.')
plot(x(), y(), 'b.')
colormap('jet')
colorbar
result:
I am using an indexed image.How do I programatically obtain the pixel intensity values obtained by changing the colormap to hsv in the imtool? Is there a way to change the colormap of the indexed image to hsv(256)?
I am new to MATLAB, kindly help!
I have attached the image below:
Which channel does the imtool display and what does the value '91' in the imtool stand for? How do I obtain this value?
The Pixel info at the bottom displays the following information:
Pixel info: (X, Y): Pixel Value
Here, we have pixel value of 91 at (309, 510). 91 is the pixel intensity in a range of values (mostly 0 to 255). Only 1 channel is being read because it is a grayscale image.
You can create a hsv image out of an RGB image but it doesnt make sense to talk of a hsv conversion for a gray scale image. What you have is a grayscale image.