CMPS1371 Introduction to Computing for Engineers PROCESSING SOUNDS.
CMPS1371 Introduction to Computing for Engineers IMAGES.
-
Upload
grace-marlene-palmer -
Category
Documents
-
view
227 -
download
3
Transcript of CMPS1371 Introduction to Computing for Engineers IMAGES.
![Page 1: CMPS1371 Introduction to Computing for Engineers IMAGES.](https://reader035.fdocuments.in/reader035/viewer/2022062305/5697c01e1a28abf838cd126f/html5/thumbnails/1.jpg)
CMPS1371Introduction to
Computing for Engineers
IMAGES
![Page 2: CMPS1371 Introduction to Computing for Engineers IMAGES.](https://reader035.fdocuments.in/reader035/viewer/2022062305/5697c01e1a28abf838cd126f/html5/thumbnails/2.jpg)
Images
Images are considered as matrices whose elements are the pixel values of the image
M rows
N columns
RED BLUE
GREEN
![Page 3: CMPS1371 Introduction to Computing for Engineers IMAGES.](https://reader035.fdocuments.in/reader035/viewer/2022062305/5697c01e1a28abf838cd126f/html5/thumbnails/3.jpg)
Images
Matlab has two main ways to represent an image that consists of M x N pixels:
RGB or “true color” image: uses an MxNx3 array where the third index contains the RGB components
Indexed color image: uses an MxN array containing integers that are the row entries in a “colormap” that defines the actual color.
![Page 4: CMPS1371 Introduction to Computing for Engineers IMAGES.](https://reader035.fdocuments.in/reader035/viewer/2022062305/5697c01e1a28abf838cd126f/html5/thumbnails/4.jpg)
RGB Color Image
• RGB: MxNx3 8-bit integer array
M r
ows
N columns
RED
BLUEGREEN Each in range 0→255
[215, 43, 62]
Divide by 255 => [0.842, 0.175, 0.246]
![Page 5: CMPS1371 Introduction to Computing for Engineers IMAGES.](https://reader035.fdocuments.in/reader035/viewer/2022062305/5697c01e1a28abf838cd126f/html5/thumbnails/5.jpg)
Indexed Color Image
• Indexed Color: MxN array with values that index into an NCx3 colormap array that contains the actual RGB colors.
M r
ows
N columns 3
256
row
s
143RED
BLUE
GREEN
[0.142, 0.375, 0.846]
![Page 6: CMPS1371 Introduction to Computing for Engineers IMAGES.](https://reader035.fdocuments.in/reader035/viewer/2022062305/5697c01e1a28abf838cd126f/html5/thumbnails/6.jpg)
Reading Image Files
Matlab can read and write data in most common image file formats:
jpeg, tif, bmp, png, etc…
A = imread(filename, fmt); reads file into an RGB image
[A,map] = imread(filename, fmt); reads file into an indexed image
![Page 7: CMPS1371 Introduction to Computing for Engineers IMAGES.](https://reader035.fdocuments.in/reader035/viewer/2022062305/5697c01e1a28abf838cd126f/html5/thumbnails/7.jpg)
Loading an Image
>> a = imread(‘picture.jpg’);
>> imshow(a);
![Page 8: CMPS1371 Introduction to Computing for Engineers IMAGES.](https://reader035.fdocuments.in/reader035/viewer/2022062305/5697c01e1a28abf838cd126f/html5/thumbnails/8.jpg)
Image Characteristics
Image (=matrix) size:size(a): 384 512 3
R G B
384
512
![Page 9: CMPS1371 Introduction to Computing for Engineers IMAGES.](https://reader035.fdocuments.in/reader035/viewer/2022062305/5697c01e1a28abf838cd126f/html5/thumbnails/9.jpg)
RED plane
A(:,:,[2 3]) = 0;
imshow(a);
![Page 10: CMPS1371 Introduction to Computing for Engineers IMAGES.](https://reader035.fdocuments.in/reader035/viewer/2022062305/5697c01e1a28abf838cd126f/html5/thumbnails/10.jpg)
GREEN plane
A(:,:,[1 3]) = 0;
imshow(a);
![Page 11: CMPS1371 Introduction to Computing for Engineers IMAGES.](https://reader035.fdocuments.in/reader035/viewer/2022062305/5697c01e1a28abf838cd126f/html5/thumbnails/11.jpg)
BLUE plane
A(:,:,[1 2]) = 0;
imshow(a);
![Page 12: CMPS1371 Introduction to Computing for Engineers IMAGES.](https://reader035.fdocuments.in/reader035/viewer/2022062305/5697c01e1a28abf838cd126f/html5/thumbnails/12.jpg)
Geometric Manipulation of Images
Let’s rearrange the pixels in the image:
<< Left/right = a(:end:-1:1,:);
<< image(Left/right)
Reversing the rows
Original
![Page 13: CMPS1371 Introduction to Computing for Engineers IMAGES.](https://reader035.fdocuments.in/reader035/viewer/2022062305/5697c01e1a28abf838cd126f/html5/thumbnails/13.jpg)
Geometric Manipulation of Images
Let’s rearrange the pixels to be upside down:
<< updown = a(end:-1:1,:,:);
<< image(updown)
Original
Reversing the columns
![Page 14: CMPS1371 Introduction to Computing for Engineers IMAGES.](https://reader035.fdocuments.in/reader035/viewer/2022062305/5697c01e1a28abf838cd126f/html5/thumbnails/14.jpg)
Geometric Manipulation of Images
Suppose we split an image into left and right halves and then replace one half with a mirror image of the other
Original
![Page 15: CMPS1371 Introduction to Computing for Engineers IMAGES.](https://reader035.fdocuments.in/reader035/viewer/2022062305/5697c01e1a28abf838cd126f/html5/thumbnails/15.jpg)
Splitting Code
function Anew = splitMirror(A)% ANEW = splitMirror(A)% Splits an image in half and % creates a mirror of the left half[Nr,Nc]=size(A);Anew=A;c2=round(Nc/2); % find midpointfor row=1:Nr for col=(c2+1):Nc cx=Nc+1-col; Anew(row,col)=A(row,cx); endend
![Page 16: CMPS1371 Introduction to Computing for Engineers IMAGES.](https://reader035.fdocuments.in/reader035/viewer/2022062305/5697c01e1a28abf838cd126f/html5/thumbnails/16.jpg)
Cute Dog Picture
![Page 17: CMPS1371 Introduction to Computing for Engineers IMAGES.](https://reader035.fdocuments.in/reader035/viewer/2022062305/5697c01e1a28abf838cd126f/html5/thumbnails/17.jpg)
Lake Scene
![Page 18: CMPS1371 Introduction to Computing for Engineers IMAGES.](https://reader035.fdocuments.in/reader035/viewer/2022062305/5697c01e1a28abf838cd126f/html5/thumbnails/18.jpg)
Collage Design
Cute Dog cropped to fitLake picture shrunk to
match
800
600
800
600
All borders 40 pixels wide
2 * 800 + 5 * 40
600
+ 4
* 4
0
R = 150G = 100B = 50
R = 255G = 255B = 200
![Page 19: CMPS1371 Introduction to Computing for Engineers IMAGES.](https://reader035.fdocuments.in/reader035/viewer/2022062305/5697c01e1a28abf838cd126f/html5/thumbnails/19.jpg)
Collage
![Page 20: CMPS1371 Introduction to Computing for Engineers IMAGES.](https://reader035.fdocuments.in/reader035/viewer/2022062305/5697c01e1a28abf838cd126f/html5/thumbnails/20.jpg)
Image Arithmetic
Adding ‘imadd’: Brighten an image
Subtracting ‘imsubtract’
Multiplying ‘immultiply’:
Multiply two images multiply image by constant:
brightens > 1, darkens < 1 Dividing
‘imdivide’
![Page 21: CMPS1371 Introduction to Computing for Engineers IMAGES.](https://reader035.fdocuments.in/reader035/viewer/2022062305/5697c01e1a28abf838cd126f/html5/thumbnails/21.jpg)
Spatial Transformations
Resizing ‘imresize’: changes the size of the
image Rotation
‘imrotate’: rotates the image by given angle
Cropping ‘imcrop’: Extract a rectangular part of
the image