Manipulating images
Lesson Objectives:
- Do transformations on an image as if it were an array.
- Select areas of an image using indexing
Now that we've imported images into Matlab and know what this looks like, we can manipulate these images. There are two different types of manipulations we can do.
- Point transformations- Where we do manipulations on individual pixels
- Overall image- Where we do transformations to extract features from the overall image.
Point transformations in MATLAB.
Remember, each pixel in an image is a cell in Matlab. An image which has 256 rows and 300 columns is 256 pixels high and 300 pixels wide and has a total of 256 x 300 pixels. We can apply point transformations to images just as we apply transformations to regular arrays. We can add, subtract, multiply and divide images.
%load in 'coins.png' which is supplied with the image processing toolbox.
coins= imread('coins.png');
% add 50 to coins and store it in a variable.
coins_50= coins+50;
% display coins and coins_50 side by side.
figure
subplot(1,2,1)
imshow(coins)
subplot(1,2,2)
imshow(coins_50)
Using indexing to define Regions of Interest (ROI)
Just like with matrices, we can also look at a part of an image using indexing. We are going to use the same image 'coins.png' we used before.
% Read in coins.png
coins= imread('coins.png');
% Get pixel information
impixelinfo
coins_indexed= coins(100:150, 100:150);% index to get out just one coin.
imshow(coins_indexed) % display indexed coin.
Challenge 1:
Fingerprints!
We have some open source fingerprint data here. Download this dataset. The challenge is to read in two of the fingerprint image files and divide one by the other. Place a rectangular ROI on the divided image so we can only look at the areas where the fingerprints are different.
Extension- Using image processing toolbox to interactively crop an image
The image processing toolbox has a function that conveniently allows us to do what we just did interactively. Use the help documentation for imcrop
to interactively crop a rectangular area around the fingerprint.