[?] Subscribe To This Site


leftimage for poohprod.ru

RGB images - an introduction to image processing algorithms

We’ll show some basic ideas on RGB images (or image processing in Matlab). These concepts are fundamental and don’t require any special toolbox.

An image in Matlab is a matrix m x n containing colors to be displayed. The colors have to be defined in a color map, which is another matrix. A color map matrix may have any number of rows, but it must have exactly three columns.

Each row is interpreted as a color, with the first element specifying the intensity of red light, the second green, and the third blue (that’s why it’s called an RGB image or matrix). Color intensity can be specified on the interval 0.0 to 1.0.

First experiment: define some colors and show them

% We can define an arbitrary group of colors to be used
colors1 = [
0 0 0
% First element = black
0 0 1 % blue
0 1 0 % green
0 1 1 % cyan
1 0 0 % red
1 0 1 % purple
1 1 0 % yellow
1 1 1]; % Last element = white

% We prepare the matrix that contains the colors to be displayed
% The list refers to the number of the elements in the color list

w = [1 2 3 4 5 6 7 8];

% We use the 'colormap' function to define the actual
% palette in our workspace


% We use the 'image' instruction to display the matrix

% We don't want to show values along the axes, for the moment
axis off

This is the image produced

rgb image 1

Second experiment: define random colors and display them (5 times)

Press any key (or click the mouse) to change the colors to be visualized...

w = [1 2 3 4 5 6 7 8];
for i = 1 : 5
colors2 = rand(8,3);
disp('Press any key to continue...')


These could be two of the five images. Since they are random colors, you’ll get different results.

rgb image 2 - random colors

rgb image 3 - another random color

Third experiment: display predefined color palettes

% There are some color palettes already defined
colors3 = {'hot' 'cool' 'jet' 'hsv' 'flag'};
for i = 1 : 5
% We get the predefined palettes (one at a time)
colormap (colors3{i})
% We create the matrix to be shown, with 64 different % elements
w = 1 : 64;
% Display the image
% Use the names of the different color groups as a title

These are two of the palettes:

color palette named 'hot'

color palette named 'jet'

Now, the interesting part is that we can process images by either modifying the color palette or modifying the appropriate element(s) in the matrix to be displayed.

In this example, we change the image by just changing the matrix w

colormap hot
w = 1:4:64;
subplot(2, 1, 1); image(w); axis

w = fliplr(w);
subplot(2, 1, 2); image(w); axis

This is the graphic result:

simple image process algorithm

From 'RGB images' to home

From 'RGB images' to 'Matlab programming'



Line Detection

footer for matlab page

Related pages

piecewise equationsmatlab basics programmingstepwise matlabalgorithm for finding gcd of two numbersmatrix multiplication matlablinspace matlab exampleboolean operators meaninghow do i convert decimal to binaryhow to plot a circle in matlabdividing two polynomialsimpluse functionoctal tablehexadecimal to octal conversion methodsimpsons rule matlabsimultaneous equations matlabascii value chartconversion binary to octalfind gcd using euclidean algorithmhow to generate random numbers in matlabgauss jordan method inversehow to call a function in matlabconvert binary to decimal formulamatlab stemcolor band resistor calculatortrapz in matlabfibonacci golden ratio calculatorconvert binary number to hexadecimalsubplot matlab exampleascii char mapgauss jordan c programhobject matlabmaclaurin polynomial calculatorsimultaneous equations solver with workingssphere function matlabcramersruletriangle plot matlabhow to input matrix in matlabmatlab surfcascii code for alphabets and numbersintegrals calculatorsolve equations in matlabhalf life formulasbmi index tablesalvage value definecompound continuous interest calculatorconverter octal to binarymatlab shadescilab functionadmittance chartnonlinear equation solver matlabascii value for alphabetssolving cubic equations in matlabboolean operators meaninggraphing with matlabbinary to hexadecimal conversion methodconversion to binary numberslagrange interpolation example problemsscilab programs examplesoctal binary convertersimpson matlabexample of pascal triangletrapezoidal rule algorithmbmi examplescramer's methodcramer's rule exampleascii symbol chartformula to calculate depreciationintegral calculator with limitsbinary to hexadecimal conversion formulasum of harmonic series formulamatlab trapezoidal methodbinary chart letterssummation matlabmatlab upper triangular matrix