• No results found

CONVERT A 8-BIT RGB IMAGE TO A GRAYSCALE IMAGE

(iii) Grayscale Image

5.16 CONVERT A 8-BIT RGB IMAGE TO A GRAYSCALE IMAGE

axis off

5.16 CONVERT A 8-BIT RGB IMAGE TO A GRAYSCALE IMAGE

8-bit color is a true direct color system. The platter can store 4, 16 or 256 distinct colors.

These limits are imposed by the architecture of the display. 256 values can fit in a single 8-bit byte. 8-bit color graphics is a method in which an image file is stored such that each pixel of the image is represented by a 8-bit byte. Thus, the maximum number of colors that can be displayed is 28 = 256. In computer one byte has 8 bits and can store 28 = 256 values ranging from 0 to 255.

In order to convert a 8-bit RGB image first, separate the color indexed image into its different RGB components. This can be done using the equations given below:

>> cd d:\pictures

>> i=imread(‘aadil.jpg’,’jpg’);

>> image(i)

>> R=i(:,:,1);

>> G=i(:,:,2);

>> B=i(:,:,3);

Next we convert the RGB matrices obtained above into a gray-scale intensity image, using the standard perceptual weightings for the three different color components red, green and blue.

>> j = 0.2989*i(:,:,1)+0.5870*i(:,:,2)+0.1140*i(:,:,3);

Or

>>j = 0.2990*R + 0.5870*G + 0.1140*B;

Then we could give the command,

>> colormap (gray (256)) image (j)

The entire program is given below.

>> cd d:\pictures

>> i=imread (‘aadil.jpg’,’jpg’);

>> image(i)

>> j = 0.2989*i (:,:,1)+0.5870*i (:,:,2)+0.1140*i (:,:,3);

>> colormap (gray (256)) image (j)

First an image is uploaded.

>> cd d:\pictures

>> i=imread (‘fog.jpg’);

>> image (i)

Then we find out the monochrome luminescence by combining the RGB values according to the NTSC standard. This applies the coefficients related to the eye’s sensitivity to TGB colors.

>> j = 0.2989*i (:,:,1)+0.5870*i (:,:,2)+0.1140*i (:,:,3);

>> colormap (gray (256))

>> image (j)

image (i) image (ii)

It should be noted here that the value in the j matrix lie within 0 and 256.

camup returns the camera up vector setting in the current axes. The camera up vector specifies the direction that is oriented up in the scene.

MATLAB Program

Output Explanation

camup ([vector]) for i=1:100 [u,v] =

meshgrid ((0:0.1:1)*pi, (0:0.1:2)*

pi);

a1=10*i*cos (v).*sin (u);

b1=10*i*sin (v).*sin (u);

sets the up vector in the current axes to the specified value. The up vector is specified as x, y, and z components in vector [x y z].

In this example the up vector in the current axis is as shown below.

camup (‘mode’) for i=1:100 [u,v] =

meshgrid ((0:0.1:1)*pi, (0:0.1:2)

*pi);

a1=10*i*cos (v).*sin (u);

b1=10*i*sin (v).*sin (u);

The camup (‘mode’) returns the current value of the camera up vector mode, which can either be auto (default) or manual.auto is the default camera up vector mode.

(0:0.1:2)*pi);

a1=10*i*cos(v).*sin(u);

b1=10*i*sin(v).*sin(u);

c1=10*i*cos(u);

surf(a1,b1,c1);

end

camup(‘auto’)

camup for i=1:100

[u,v] =

meshgrid((0:0.1:1)*pi, (0:0.1:2)*pi);

a1=10*i*cos(v).*sin(u);

b1=10*i*sin(v).*sin(u);

ans = 0 0 1

>>

The camup returns the camera up vector setting in the current axes. The camera up vector specifies the direction that is oriented up in the scene.

c1=10*i*cos(u);

surf(a1,b1,c1);

end

>> camup

A few more examples using the camup function are given below.

MATLAB

Commands Output The up vector specified as x, y, and z components in vector [x y z] is shown below

>> surf (peaks)

>> xlabel (‘X-Axis’);

>> ylabel (‘Y-Axis’);

>> zlabel (‘Z-Axis’);

>> camup ([1 0 1])

>> camup ([1 1 1])

>> camup ([0 0 1])

>> camup ([0 1 1])

5.18 rotate

The function rotate in MATLAB rotates a graphics object in three-dimensional space about a specified direction according to the right-hand rule. It should be noted that the graphics object which we want to rotate must be a child of the same axes. The axis of rotation is defined by an origin and a point P relative to the origin. P can be expressed in the spherical coordinates using the [theta phi] angles, or in Cartesian coordinate.

rotate (h, direction, angle) rotates the graphics object h by angle degrees about an axis of rotation the direction of which is a two- or three-element vector that described in conjunction with the origin. For example,

>> h=surf (peaks (50));

>> rotate (h, [1 1 1],90)

rotate (…,origin) specifies the origin of the axis of rotation as a three-element vector. The default origin is the center of the plot box.

>> h = surf (peaks(50));

>> center = [50 50 50];

>> rotate (h,[1 1 1],90,center)

Here the data of the object is modified by the rotation transformation whereas

in view and rotate3d only the viewpoint is modified.

Few examples illustrating the use of rotate function to rotate a surface in three-dimensional space is given below.

MATLAB Commands Output

>> ima=peaks (20);

>> sr=surf (ima);

>> sr=surf (ima);

>> dir=[1 1 1];

>> rotate (sr,dir,30)

>>

>> rotate (sr,dir,90)

rotate (sr,dir,80)

>> ima=peaks (20);

>> sr=surf (ima);

>> dir=[1 0 0];

>> rotate (sr,dir,80)

>>

5.19 Colormaps

In MATLAB colormaps are 3 by m arrays consisting of double precision floating point numbers. The numbers are in the range of 0 to 1. MATLAB color maps cannot have integer values. True color images of class double have data values which are floating point numbers in the range of 0 to 1. In true color image of class unit8 the data values are integer numbers in the range 0 to 255 and for true color images of class unit16 the data lies in the range of 0 to 65535. A .jpg format file is loaded. This image is displayed as a transformed intensity image as a heat map.

A colormap is an m-by-3 matrix of real numbers between lying between 0.0 and 1.0.

The i-th row of the colormap matrix defines the i-th color by specifying the intensity of

red, green and blue.

For example,

map (i,:) = [r (i) g (i) b (i)].

[0 0 0] would give black and [1 1 1] would give white.

colormap (map) will set the colormap to the matrix map. An error message is shown in case a value is not in the interval 0 to 1.

colormap (‘default’) and colormap (hsv) set the current colormap to the default colormap.

map = colormap shows the current colormap being used.

MATLAB Command

Output Explanation

surf (peaks) colormap (pink)

The pinkcolormap contains pastel shades of pink. The pinkcolormap provides sepia tone colorization of grayscale photographs.

The hsv colormap varies the hue component of the hue-saturation-value color model. The colors begin with red, pass through yellow, green, cyan, blue, magenta, and return to red. The

The flag colormap consists of the colors red, white, blue, and black. This colormap completely changes color with each index increment.

colormap (‘default’)

The jet colormap is the default colormap in MATLAB.

A digital image has been shown using various colormaps.

MATLAB Command

Output Explanation

>> cd d:\pictures i=imread (‘bird.jpg’);

>> image (i)

>> cd d:\pictures

>> i=imread (‘bird.jpg’);

>>

imean=mean(i,3);

>> image (imean)

Original image

>> colormap (hot (256))

The hot colormap varies smoothly from black through shades of red, orange, and yellow, to white.

>>

colormap(copper)

The coppercolormap varies smoothly from black to bright copper.

>> colormap(jet) The jet colormap ranges from blue to red, and passes through the colors cyan, yellow, and orange. It is a variation of the hsv colormap. The jet colormap is associated with an astrophysical fluid jet simulation from the National Center for Supercomputer Applications.

It is also possible to get the complement of a colormap. For example:

>> cd d:\pictures

>> i=imread (‘bird.jpg’);

>> image (i)

>> j=255-i;

>> image (j)

Related documents