
- •Introduction to image processing in Matlab 1
- •Introduction
- •Fundamentals
- •Image formats supported by Matlab
- •Working formats in Matlab
- •Intensity image (gray scale image)
- •Binary image
- •Indexed image
- •Rgb image
- •Multiframe image
- •How to convert between different formats
- •How to convert between double and uint8
- •How to read files
- •Loading and saving variables in Matlab
- •Examples
- •Example 1.
- •Example 2
- •How to display an image in Matlab
- •Exercise
- •Indexed Color and Palettes
- •Iminfo('filename')
- •2. Creating the Negative of an Image
- •3. Rgb Components of an Image
- •4. Gamma Scaling of an Image
- •5. Converting an Image to Grayscale
- •6. Brightening an Image
- •7. Creating a Histogram of an Image
- •8. Dither an Image
5. Converting an Image to Grayscale
MatLab allows us to change a color image into a grayscale image with ease. One way to
do this is to make all the values of the RGB components equal. MatLab provides a
function to do this.
Simply type the following:
grayimage = rgb2gray(Myimage);
figure;
imshow(grayimage);
The new image formed is in gray scale. The rgb2gray() function does exactly what it
says, changes the RGB image into gray; it basically forces all the RGB components to be
equal.
6. Brightening an Image
Another very useful and easy function that MatLab provides us is the function to brighten
an image. However, keep in mind that this function can be used only with the grayscale
images.
Simply type the following command after reading in the image, scaling it to gray, and
viewing it.
brighten(beta); % Set beta to any value between -1.0 and 1.0
We will see how to brighten a colored image in a later lab.
7. Creating a Histogram of an Image
An image histogram is a chart that shows the distribution of the different intensities in an
image. Each color level is represented, as a point on x-axis and on y-axis is the number of
instances of color level repetitions in the image. A histogram may be viewed with the
imhist() command. Sometimes all the important information in an image lies only in a
small region of colors, hence it is usually difficult to extract information from the image.
To balance the brightness level of an image, we carryout an image processing operation
termed histogram equalization. (This method usually increases the global contrast of many images, especially when the usable data of the image is represented by close contrast values. Through this adjustment, the intensities can be better distributed on the histogram. This allows for areas of lower local contrast to gain a higher contrast. Histogram equalization accomplishes this by effectively spreading out the most frequent intensity values.)
In order to see the histogram of your favorite image use the following steps:
Myimage = imread('image'); % Read in your favorite image
figure; % Create figure to place image on
imshow(Myimage); % View the image
figure; % Create another figure for the histogram
imhist(Myimage); % Draw the histogram chart
[eqImage, T]=histeq(Myimage); % Equalize the image, that is
% equalize the intensity of the pixels
% of the image
figure; % Create another figure to place the image
imshow(eqImage); % Draw the equalized image
figure; % Create a figure for the histogram
imhist(eqImage); % Draw the equalized histogram
figure; % Create another figure to place a plot
plot((0:255)/255, T); % Plot the graph of the vector T
The vector T should contain integer counts for equally spaced bins with intensity values
in the appropriate range: [0, 1] for images of class double, [0, 255] for images of class
uint8, and [0, 65535] for images of class uint16.
8. Dither an Image
Dithering is a color reproduction technique in which dots or pixels are arranged in such a
way that allows us to perceive more colors than are actually used. This method of
"creating" a large color palette with a limited set of colors is often used in computer
images, television, and the printing industry. Images in MatLab can be dithered by using
the predefined functions. One easy way to do this is as follows:
figure('Name', 'Myimage - indexed, no dither');
[Myimagenodither, Myimagenodithermap]=rgb2ind(Myimage, 16, 'nodither');
imshow(Myimagenodither, Myimagenodithermap);
figure('Name', 'Myimage - indexed, dithered');
[Myimagedither, Myimagedithermap] = rgb2ind(Myimage, 16, 'dither');
imshow(Myimagedither, Myimagedithermap);
Type the above commands in the MatLab command prompt and check the images.
How do they differ? Do you feel one is better than the other? Which one seems a bit more
detailed? Comment on all your findings.
When finished, feel free to experiment, discover, learn and have fun….it is all about how
much you like to play and learning starts to happen as you have fun. Challenge yourself
and learn. Report and comment all of your finding.
Дизеринг, дитеринг (англ. dither от староанглийского didderen — дрожать) — при обработке цифровых сигналов представляет собой подмешивание в первичный сигнал псевдослучайного шума со специально подобранным спектром. Применяется при обработке цифрового звука, видео и графической информации для уменьшения негативного эффекта от квантования.
Контраст изображения, диапазон яркостей изображения — отношение яркостей самой светлой и самой тёмной частей изображения.