Computer Vision_Matlab (1)

1 Loading Images from Files

Ia=imread('rooster.jpg');
Ib=imread('elephant.png');

1.1 Intensity images

double---0.0(black)-1.0(white)

unit 8---0-255

The class uint8 only requires roughly 1/8 of the storage compared to the class double.

1.2 Binary images

 0 or 1

1.3 RGB images

3-dimensional matrix

red green and blue

floating-point numbers or as integer values

1.4 Indexed images

two matrices

the first matrix has the same size as the image and one number for each pixel

the second matrix is called the colour map and its size may be different from the image

I1=rand(1000,1000);
I2=rand(1000,1000);
Isum=I1+I2;
ImultA=I1*I2;
ImultB=I1.*I2;
Ia=imread('rooster.jpg');
Ib=imread('elephant.png');

type whos

2 Image Display

Ia=imread('rooster.jpg');
Ib=imread('elephant.png');
figure(1), subplot(2,2,1), imagesc(Ia); title('RGB image'); 

Ia=imread('rooster.jpg');
Ib=imread('elephant.png');
figure(1), subplot(2,2,1), imagesc(Ia); title('RGB image'); 
subplot(2,2,2), imagesc(Ia(:,:,1)); title('red channel'); colorbar
subplot(2,2,3), imagesc(Ia(:,:,2)); title('green channel'); colorbar
subplot(2,2,4), imagesc(Ia(:,:,3)); title('blue channel'); colorbar

colormap('gray')

figure(2), imagesc(Ib); colorbar
colormap('gray');

figure(2), axis('off')

axis('equal')

# This reshapes the image so that both the x- and y-axes are scaled equally

3 Reading Values From An Image

Ib
Ib (3,:)   # 3rd row
Ib (:,3)   # 3rd column
Ib (1:6; 1:4)   # 1-6 row and 1-4 column (6*4 matrix)
Ia (1:6,1:4,1)   # red channel
Ia (1:6,1:4,2)   # green channel
Ib (3,4)   #  row 3 and column 4
# from RGB format to indexed format
rgb2ind()

# from RGB format to intensity format
rgb2gray()

# from RGB format to binary format
im2bw()

# from indexed format to RGB format
ind2rgb()

# from indexed format to intensity format
ind2gray()

# from indexed format to binary format
im2bw()

# from intensity format to indexed format
gray2ind()

# from intensity format to binary format
im2bw()

# from a matrix to intensity format by scaling
mat2gray()

# from uint8 to double data type
im2double()

# from double to uint8 data type
im2uint8()

# from RGB to HSV format
rgb2hsv()

# from RGB to Lab format
rgb2lab()

4 Saving Images and Variables to Files

Iag=rgb2gray(Ia);
Iagd=im2double(Iag);

imwrite(Iagd,'rooster_gray.jpg','jpg')    # save a MATLAB image as a file

figure(1)   # save figure
print -dpdf rooster_RGB.pdf   # creat a .pdf file
help print    

save   # save the variables in your current MATLAB session so that you can
       # continue work with them a later date
save('cv_cw1_variables.mat');
load

Addition

A.1 

I1=rand(1000,1000)

I2=rand(1000,1000);

The first command (without the semi-colon) prints lots of numbers to the screen, while the second command (with the semi-colon) does not.

A.2

ImultA=I1*I2;

ImultA=I1*I2;

# Be sure to use .* instead of * when you are multiplying two images together element-by-element.

A.3

Reading an image into MATLAB is performed by the function imread . This function supports a number of image file formats (these formats can be listed by executing the command imformats

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值