Yeni Laraswati
Yeni Laraswati
Yeni Laraswati
Disusun Oleh:
Nama : Yeni Laraswati (09011181520029)
Jurusan :Sistem Komputer
Dosen rwin, M.Si
:E
4. Convert the indexed image X with color map map to an intensity image.
X_gray = ind2gray(X,map);
5. We can verify that the new intensity image consists of pixel values in the range
[0, 255].
max(X_gray(:))
min(X_gray(:))
8. Display the indexed image trees.tif. The image data are stored in variable X and the color map
in map. Note that the impixelinfo option provides a clear hint that this is an indexed color image.
imshow(X,map), impixelinfo
9. Use theimpixelfunction to explore interactively the pixel contents of selected points in the
image. Use the mouse to click on the points of interest: normal button clicks are used to select
pixels, pressing Backspace or Delete removes the previously selected pixel, a double-click adds
a final pixel and ends the selection, and pressing Return finishes the selection without adding a
final pixel.
RGB = imread(’peppers.png’);
[c,r,p] = impixel(RGB);
10. Use the improfile function to explore the contents of a line in the coins.png image that is
currently loaded in the variable I.
r1 = 17; c1 = 18; r2 = 201; c2 = 286;
imshow(I)
line([c1, c2], [r1, r2], ’Color’, ’g’, ’LineWidth’, 2);
figure
improfile(I, [c1, c2], [r1, r2]);
ylabel(’Gray level’);
11. Use the imtool function to display the image currently loaded in the variable X_rgb. Note
that a secondary window (Overview) will open as well. Explore the additional functionality,
including the possibility of measuring distances between two points within the image.
imtool(X_rgb)
15. Display the coins.png (loaded in variable I) and the trees.tif (loaded in variable X and its
color map in variable map) images in a subplot. Execute each statement at a time to see the effect
on the images as they are displayed.
figure
subplot(1,2,1), imshow(I)
subplot(1,2,2), imshow(X,map)
16. Use the subimage function to display multiple images with different color maps.
figure
subplot(1,2,1), subimage(I), axis off
subplot(1,2,2), subimage(X,map), axis off
17. Manually convert the intensity image coins (loaded in the variable I) to an indexed image and
then to RGB. Note that the trees image (loaded in variable X with its color map in variable map)
has already been converted to RGB in
step 3 (saved in variable X_rgb).
[I_ind,I_map] = gray2ind(I,256);
I_rgb = ind2rgb(I_ind,I_map);
18. Display the truecolor images using the imshow function.
figure
subplot(1,2,1), imshow(I_rgb)
subplot(1,2,2), imshow(X_rgb)
19. Use imwrite to save two of the modified images in this tutorial to files for further use. Use
the JPEG format for one of them and the PNG extension for
the other. For example,
imwrite(X_rgb, ’rgb_trees.jpg’);
imwrite(X_gray, ’gray_trees.png’);
2. 6.3 Tutorial 6.1: Arithmetic Operations / 113
1. Use the imadd function to brighten an image by adding a constant (scalar)
value to all its pixel values.
I = imread(’tire.tif’);
I2 = imadd(I,75);
figure
subplot(1,2,1), imshow(I), title(’Original Image’);
subplot(1,2,2), imshow(I2), title(’Brighter Image’);
2. Use the imadd function to blend two images.
Ia = imread(’rice.png’);
Ib = imread(’cameraman.tif’);
Ic = imadd(Ia,Ib);
figure
imshow(Ic);
6. Use the zoom tool to zoom into the right area of the difference image about
halfway down the image. You will notice that a small region of pixels is faintly
white.
7. To zoom back out, double-click anywhere on the image.
8. Calculate the absolute difference. Make sure Figure 2 is selected before executing
this code.
diffim2 = imabsdiff(I,J);
subplot(2,2,2), imshow(diffim2), title(’Abs Diff Image’);
11. Use the zoom tool to see the differences between all four difference images
12. Close all open figures and clear all workspace variables.
13. Use immultiply to dynamically scale the moon image.
I = imread(’moon.tif’);
I2 = imadd(I,50);
I3 = immultiply(I,1.2);
figure
subplot(1,3,1), imshow(I), title(’Original Image’);
subplot(1,3,2), imshow(I2), title(’Normal Brightening’);
subplot(1,3,3), imshow(I3), title(’Dynamic Scaling’);
14. Close all open figures and clear all workspace variables.
15. Create an artificial 3D planet by using the immultiply function to multiply
the earth1 and earth2 images.
I = im2double(imread(’earth1.tif’));
J = im2double(imread(’earth2.tif’));
K = immultiply(I,J);
figure
subplot(1,3,1), imshow(I), title(’Planet Image’);
(1,3,2), imshow(J), title(’Gradient’);
subplot(1,3,3), imshow(K,[]), title(’3D Planet’);
16. Close all open figures and clear all workspace variables.
17. Use image division to dynamically darken the moon image.
I = imread(’moon.tif’);
I2 = imdivide(I,2);
Figure
subplot(1,3,1), imshow(I), title(’Original Image’);
subplot(1,3,2), imshow(I2), title(’Darker Image w/ Division’)
19. Close all open figures and clear all workspace variables.
20. Load the images that will be used for background subtraction.
notext = imread(’gradient.tif’);
text = imread(’gradient_with_text.tif’);
figure, imshow(text), title(’Original Image’);
4. Use the bitand function to compute the logic AND between the original
image and the new mask image.
I2 = bitand(I,bw2);
imshow(I2);
5. Use the bitcmp function to generate a complemented version of the bw2 mask.
bw_cmp = bitcmp(bw2);
figure
subplot(1,2,1), imshow(bw2), title(’Original Mask’);
subplot(1,2,2), imshow(bw_cmp), title(’Complemented Mask’);
6. Use bitor to compute the logic OR between the original image and the complemented
mask.
I3 = bitor(I,bw_cmp);
figure, imshow(I3)
10. Close all open figures and clear all workspace variables.
11. Read in image and calculate an adjusted image that is darker using the imdivide function.
I = imread(’lindsay.tif’);
I_adj = imdivide(I,1.5);
13. Use logic operators to show the darker image only within the region of interest, while
displaying the original image elsewhere.
bw_cmp = bitcmp(bw); %mask complement
roi = bitor(I_adj,bw_cmp); %roi image
not_roi = bitor(I,bw); %non_roi image
new_img = bitand(roi,not_roi); %generate new image
imshow(new_img) %display new image
3. 7.6 Tutorial 7.1: Image Cropping, Resizing, Flipping,
and Rotation / 138
1. Open the cameraman image and use the Crop Image option in the Image Tool
(imtool) toolbar to crop it such that only the portion of the image containing
the tallest building in the background is selected to become the cropped image.
Pay attention to (and write down) the coordinates of the top left and bottom
right corners as you select the rectangular area to be cropped. You will need
this information for the next step.
2. Double-click inside the selected area to complete the cropping operation.
3. Save the resulting image using the File > Save as... option in the imtool
menu. Call it cropped_building.png.
I = imread(’cameraman.tif’);
imtool(I)
14. Close all open figures and clear all workspace variables.
15. Flip the cameraman image upside down.
16. Flip the cameraman image from left to right.
I = imread(’cameraman.tif’);
J = flipud(I);
K = fliplr(I);
subplot(1,3,1), imshow(I), title(’Original image’)
subplot(1,3,2), imshow(J), title(’Flipped upside-down’)
subplot(1,3,3), imshow(K), title(’Flipped left-right’)
17. Close all open figures and clear all workspace variables.
18. Rotate the eight image by an angle of 35◦.
I = imread(’eight.tif’);
I_rot = imrotate(I,35);
imshow(I_rot);
7. Compare the resulting image with the one you had obtained using imrotate.
I1 = imread(’cameraman.tif’);
theta = 35*pi/180
xform = [cos(theta) sin(theta) 0; -sin(theta) cos(theta) 0; 0 0 1]’
T = maketform(’affine’,xform);
I4 = imtransform(I1, T);
imshow(I4), title(’Using affine transformation’)
I5 = imrotate(I1, 35);
figure, imshow(I5), title(’Using image rotating’)
14. Open the base image (Figure 7.9a) and the unregistered image (Figure 7.9b).
base = imread(’klcc_a.png’);
unregistered = imread(’klcc_b.png’);
15. Specify control points in both images using cpselect (Figure 7.10). This is an
interactive process that is explained in detail in the IPT online documentation.
For the purpose of this tutorial, we will perform the following:
• Open the Control Point Selection tool.
• Choose a zoom value that is appropriate and lock the ratio.
• Select the Control Point Selection tool in the toolbar.
• Select a total of 10 control points per image, making sure that after we select
a point in one image with click on the corresponding point in the other image,
thereby establishing a match for that point. See Figure 7.11 for the points I
chose.
• Save the resulting control points using the File > Export Points to
Workspace option in the menu.
cpselect(unregistered, base);
18. This is a critical step.We need to specify the type of transformation we want to apply to the
unregistered image based on the type of distortion that it contains. In this case, since the
distortion appears to be a combination of translation, rotation, and scaling, we shall use the
’nonreflective similarity’ transformation type. This type requires only two pairs of control points.
19. Once we have selected the type of transformation, we can determine its parameters
using cp2tform.
20. Use the resulting tform structure to align the unregistered image (using
imtransform).
% Select the type of transformation
mytform1 = cp2tform(input_points,base_points,...
’nonreflective similarity’);
% Transform
% Transform the unregistered image
info = imfinfo(’klcc_a.png’);
registered = imtransform(unregistered,mytform1,...
’XData’,[1 info.Width], ’YData’,[1 info.Height]);
21. Display the registered image overlaid on top of the base image.
figure, imshow(registered);
hold on
h = imshow(base);
set(h, ’AlphaData’, 0.6)
2. Use the transformation function on the moon image to see how the identity
function works.
I = imread(’moon.tif’);
I_adj = x(I + 1);
figure, subplot(1,2,1), imshow(I), title(’Original Image’);
subplot(1,2,2), imshow(I_adj), title(’Adjusted Image’);
3. Create a negative transformation function and show the result after applied to
the moon image.
y = uint8(255:-1:0); I_neg = y(I + 1);
figure, subplot(1,3,1), plot(y), ...
title(’Transformation Function’), xlim([0 255]), ylim([0 255]);
subplot(1,3,2), imshow(I), title(’Original Image’);
subplot(1,3,3), imshow(I_neg), title(’Negative Image’);
4. Complement the original image and show that it is equivalent to the negative
image generated in the previous step.
I_cmp = imcomplement(I);
I_dif = imabsdiff(I_cmp,I_neg);
figure, imshow(I_cmp)
figure, imshow(I_dif,[])
5. Close all open figures and clear all workspace variables.
6. Generate a logarithmic transformation function.
x = 0:255; c = 255 / log(256);
y = c * log(x + 1);
figure, subplot(2,2,1), plot(y), ...
title(’Log Mapping Function’), axis tight, axis square
7. Use the transformation function to generate the adjusted image.
I = imread(’radio.tif’);
I_log = uint8(y(I + 1));
subplot(2,2,2), imshow(I), title(’Original Image’);
subplot(2,2,3), imshow(I_log), title(’Adjusted Image’);
14. Use the nt h power transformation to undo our previous transformation.
I_power = uint8(power(I_root + 1));
subplot(1,2,2), imshow(I_power), title(’Adjusted Image’);
15. Close all open figures and clear all workspace variables.
16. Load the micro image and display it.
I = imread(’micro.tif’);
figure, subplot(1,3,1), imshow(I), title(’Original Image’);
19. Create a new transformation function and display the adjusted image.
z(1:175) = 50;
z(176:200) = 250;
z(201:256) = 50;
I3 = uint8(z(I + 1));
figure, subplot(1,2,1), plot(z), ...
xlim([0 255]), ylim([0 255]), axis square
subplot(1,2,2), imshow(I3)
20. Review the help information for glsdemo.
21. Run glsdemo with the image micro.tif and recreate the transformation
functions that we previously used in steps 17 and 19.
3. Get the values of each bin in the histogram for later use.
c = imhist(I,32);
12. Display a plot graph for both standard and normalized histogram data.
figure, subplot(1,2,1), plot(c), axis auto, title(’Plot Graph’)
subplot(1,2,2), plot(c_norm), axis auto, ...
title(’Normalized Plot Graph’)
9. The transformation function can also be obtained without using the cumsum
function.
[newmap, T] = histeq(I);
figure, plot(T)
10. Close any open figures and clear all workspace variables.
11. Prepare a subplot and display original image and its histogram.
img1 = imread(’pout.tif’);
figure, subplot(3,3,1), imshow(img1), title(’Original Image’)
subplot(3,3,2), imhist(img1), title(’Original Histogram’)
12. Display the image after histogram equalization for comparison.
img1_eq = histeq(img1); m1 = ones(1,256)*0.5;
subplot(3,3,4), imshow(img1_eq), title(’Equalized Image’)
subplot(3,3,5), imhist(img1_eq), title(’Equalized Histogram’)
subplot(3,3,6), plot(m1), title(’Desired Histogram Shape’), ...
ylim([0 1]), xlim([1 256])
13. Display matched image where the desired histogram shape is a straight line
from (0, 0) to (1, 1).
m2 = linspace(0,1,256); img2 = histeq(img1,m2);
subplot(3,3,7), imshow(img2), title(’Matched Image’)
subplot(3,3,8), imhist(img2), title(’Matched Histogram’)
subplot(3,3,9), plot(m2), title(’Desired Histogram Shape’), ...
ylim([0 1]), xlim([1 256])
14. Close any open figures and clear all workspace variables.
15. Run the Interactive Histogram Matching d emo.
Ihmdemo
16. Experiment with creating your own desired histogram shape. To create new
points on the function curve, click the curve at the desired location. To move
a point, press and drag the point. To delete a point, simply click it.
17. Perform local histogram equalization on the coins image.
9. Display the transformation function for the adjustment performed in the previous
step.
10. Close any open figures.
11. Perform histogram shrinking with a gamma value of 2.
6.10.7 Tutorial 10.1: Convolution and Correlation / 223
Specify the two matrices to be used.
a = [0 0 0 1 0 0 0];
f = [1 2 3 4 5];
5. Filter the original image with the new, nonuniform averaging mask.
6. Create a Gaussian filter and display the kernel as a 3D plot.
2. Create a Laplacian kernel and apply it to the image using the imfilter
function.
5. Use the composite Laplacian mask to perform image sharpening in one step
6. Close all open figures and clear all workspace variables.
7. Load the moon image and generate the blurred image
10. Stretch the sharpened image histogram to the full dynamic grayscale range and display the
final result.
11. Subtract the blurred image from the original image to generate a sharpening image.
12. Add sharpening image to original image to produce the final result.
14. Apply the mask to the original image to create a sharper image.
15. Close any open figures.
16. Create a high-boost mask (where A = 1) and apply it to the moon image
17. Show that a high-boost mask when A = 3 looks similar to the image simply multiplied by 3.
7.11.5 Tutorial 11.1: 2D Fourier Transform / 252
1. Load the cameraman image, convert it to double (one of the data classes
accepted as an input to fft2), and generate its FT.
2. Apply an averaging filter to the image using the default kernel size (3 × 3).
f1 = fspecial('average');
I_blur1 = imfilter(In,f1);
6. Filter the salt noise affected image using −1 for the value of r.
I_fix1 = nlfilter(I_salt,[3 3],@c_harmonic,-1);
subplot(2,3,5), imshow(I_fix1), title(’Salt Removed, r = -1’);
5. Erode the original image with a 3 × 3 structuring element and display the results.
6.Erode the original image with a 1 × 7 structuring element
10. Use bwmorph to thin the original image with five iterations.
11. Thicken the original image with five iterations.
4. Extract the edges from the test image using the Sobel edge detector.
5. Extract the edges from the test image with Gaussian noise using the Sobel edge
detector.
6. Extract the edges from the test image with the Sobel operator with no thinning
11. 15.5 Tutorial 15.1: Image Thresholding / 379
1. Load and display the test image
2. Display a histogram plot of the coins image to determine what threshold level
to use.
14. Perform adaptive thresholding by entering the following command in the command
window. Note that it may take a moment to perform the calculation, so
be patient.
I_thresh = blkproc(I,[10 10],@adapt_thresh);
15. Display the original and new image.
12. 16.6 Tutorial 16.1: Pseudocolor Image Processing / 419
1. Load the onions.png image and display its RGB components
4. Apply a smoothing filter to each component and then reconstruct the image