How to use transformation T from histeq in Matlab? - matlab

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);

Related

Convert grayscale uint8 image to RGB uint8 image

I have a code to run, which uses an original image and a mask image. The code assumes that the original image is RGB, but my original image is gray scale. This must be the result of the MATLAB whos command when I run the code:
Name Size Bytes Class Attributes
mask 308x206 63448 logical
origImg 308x206x3 190344 uint8
The mask is produced by making part of the image white and the rest is black (in a simple software like windows paint).
I want to use a gray-scale image as the origImg and produce the mask from the origImg in windows paint, but the result of the MATLAB whos command is as follows when I want to use custom photos with attributes as I said:
Name Size Bytes Class Attributes
mask 490x640x3 940800 uint8
origImg 490x640 313600 uint8
I have to convert the origImage dimension to x3 and remove the x3 from the mask, and also convert its class from unit8 to logical. In that case, I think that the code should work properly.
What should I do here in order to prepare the origImg and mask for that goal?
origImg=imread('G:\the_path\to\my_custom\image.png');
mask=imread('G:\the_path\to\my_custom\image_mask.png');
% I have to do something here to make it work.
whos;
% Rest of the code...
I am not sure if I understand you correctly.
To make a RGB image out of a gray-scale image, which still shows up as a gray-scale image, you can use
origImg = repmat(origImg,1,1,3);
which just repeats your gray-scale image for every channel of the RGB image.
For the mask, you have to do the opposite. since I don't know your image_mask.png file, I assume that it is a RGB image that uses only black and white. In this case, all three channels are the same and you could simply use one of them for the mask, doesn't matter which one:
mask = mask(:,:,1);
To convert it to logical, use
mask=logical(mask);

imnoise gaussian and dct2() in matlab

I'm trying to do dicrete cosine transformation on black and white image and also I'm trying to do that transformation on the same image but with some noise on it. The problem is that imnoise adds "RGB noise" I would say, and because of that I cant do dct2() on my image. Easy example that I tried:
B = imnoise(A,'gaussian');
C = dct2(B);
How can I put noise on my image so it stays in grayscale mode?

2-Dimensional Fast Fourier Transform 3-D plot in Matlab

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:

Generate image in particular colormap in Matlab

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)?

How to display an image's matrix in MATLAB?

How can we display an image's matrix in MATLAB?
I have read the image using imread and have converted it into binary image. How do I see an image's matrix?
If you want to see the actual matrix, use disp(I) where I is the image. If you want to view it as an image, use imagesc(I) or imshow(I).