MATLAB realization of the algebra image

@
Algebraic manipulation of the image has been widely used in image processing, in addition to its own can achieve the required arithmetic operations, but also provide a lot of preparation for complex image processing. For example, subtraction images can be used to detect an error of the same scene or object generated two or more sub-images. MATLAB may be used substantially arithmetic operators (+, -, *, /) to perform arithmetic operations of the image, but before converting the image must be double-precision type suitable for basic operations. In MATLAB, the image operation function no longer necessary to convert between data types, which functions to receive data and uint8 uint16, and returns the result of the same image format.
The following table is a common set of functions MATLAB image calculation.




















Common MATLAB image operation function
Function name Functional Description
Imabsdiff For calculating the absolute difference of the two images
imcomplement It used to make up an image
imlincomb For calculating a linear combination of the two images

Algebra function image taken using the following rule results meet the requirements of the operational range of data: data beyond the range of data to be intercepted shaping extreme value data range, the result is rounded score. Whichever algebra for two equal size must ensure that the input image, and the same type.

1. complement operation on various types of image processing

clear 
close all
clc
bw=imread('circbw.tif');
bw2=imcomplement(bw);
subplot(231)
imshow(bw)
title('二值原始图像')
subplot(234)
imshow(bw2)
title('二值图像求补')
I=imread('cell.tif');
J=imcomplement(I);
subplot(232)
imshow(I)
title('原始图像灰度图像')
subplot(235)
imshow(J)
title('灰度图像求补')
RGB=imread('onion.png');
RGB1=imcomplement(RGB);
subplot(233)
imshow(RGB)
title('RGB原始图像')
subplot(236)
imshow(RGB1)
title('RGB图像求补')

Here Insert Picture Description

2. Using the function imlincomb gray value image is enlarged 1.5 times

clear 
clc
close all
I=imread('pout.tif');
J=imlincomb(1.5,I);
subplot(121);
imshow(I)
title('原始图像')
subplot(122)
imshow(J)
title('放大1.5倍后的图像')

Here Insert Picture Description

3. The average calculation using the two images imlincomb function.

clear
clc
close all
A1=imread('rice.png');
A2=imread('cameraman.tif');
K=imlincomb(0.3,A1,0.3,A2);
subplot(131)
subimage(A1)
title('原始图像rice')
subplot(132)
subimage(A2)
title('原始图像cameraman')
subplot(133)
subimage(K)
title('图像平均')

The image of the adder

Adding generally used image multiple images of the same scene superimposed image averaging, in order to effectively reduce the additive random noise. In MATLAB, imadd adding function for realizing image, the function call format is as follows:

Z=imadd(X,Y):将矩阵X中的每一个元素与矩阵Y中对应的元素相加,返回值为Z
clear
clc
close all
I=imread('rice.png');
J=imread('cameraman.tif');
K=imadd(I,J,'uint16');%图像相加,并把结果存为16位的形式
subplot(131)
imshow(I)
title('rice原始图像')
subplot(132)
imshow(J)
title('cameraman原始图像')
subplot(133)
imshow(K,[]);%注意把结果压缩到0~255范围内显示
title('相加图像')

Here Insert Picture Description

5. Use imnoise noise addition operation function

clear 
close all
clc
a=imread('pout.tif');
a1=imnoise(a,'gaussian',0,0.007);
a2=imnoise(a,'gaussian',0,0.007);
a3=imnoise(a,'gaussian',0,0.007);
a4=imnoise(a,'gaussian',0,0.007);
K=imlincomb(0.25,a1,0.25,a2,0.25,a3,0.25,a4);
subplot(131)
imshow(a)
subplot(132)
imshow(a1)
subplot(133)
imshow(K)

Here Insert Picture Description

6. subtraction image

Image subtraction is also referred to as differential operation, and is often used to detect changes in the motion of the object. In Matlab can be directly implemented subtraction image array, you can call functions to achieve imsubtract. The function call format is as follows:

Z=imsubtract(X,Y):将矩阵X中的每一个元素与矩阵Y中对应的元素相减,返回值为Z
clear 
close all
clc
i=imread('eight.tif');
subplot(221)
imshow(i)
back=imopen(i,strel('disk',15));
subplot(222)
imshow(back)
i1=imsubtract(i,back);
subplot(223)
imshow(i1)
i2=imsubtract(i,45);
subplot(224)
imshow(i2)

7. The use of two types of functions to the image subtraction and absolute value

clear 
close all
clc
coins=imread('coins.png');
background=imopen(coins,strel('disk',15));
coins1=imsubtract(coins,background);
subplot(221)
imshow(coins)
title('原始图像')
subplot(222)
imshow(background)
title('背景图像')
subplot(223)
imshow(coins1)
title('imsubtract函数相减结果')
K=imabsdiff(coins,background);
subplot(224)
imshow(K,[])
title('imabsdiff函数相减结果')

Here Insert Picture Description

8. Reducing the luminance of the image R

clear 
close all
clc
R=imread('peppers.png');
R2=imsubtract(R,100);
subplot(121)
imshow(R)
title('原始图像')
subplot(122)
imshow(R2)
title('降低后的图像')

Here Insert Picture Description

The image multiplication

Multiplication of the image is mainly used for a mask for processing an image, i.e., masking off portions of the image. Zoom image refers to an image is multiplied by a constant. If the scaling factor is greater than 1, it will enhance the image brightness; if the factor is less than 1, will make the image darker. In MATLAB, immultiply for realizing the function of multiplying the two images. The function call format is as follows:

Z=immultiply(X,Y):将矩阵X中的每一个元素与矩阵Y中的元素对应相乘,返回值为Z
clear 
close all
clc
I=imread('rice.png');
I1=uint16(I);
I2=immultiply(I1,I1);%图像自乘
I3=immultiply(I,1.5);%图像扩大像素
I4=immultiply(I,0.5);%图像缩小像素
subplot(221)
imshow(I)
title('原始图像')
subplot(222)
imshow(I2)
title('图像自乘')
subplot(223)
imshow(I3)
title('图像扩大像素')
subplot(224)
imshow(I4)
title('图像缩小像素')

Here Insert Picture Description

10. The image division

Division of the image due to the deviation correction for the illumination sensor or adverse nonlinear effects caused, in addition to the image division ratio for generating a further image, function calls imdivide two images divided in MATLAB. Call the following format:

Z=imdivide(X,Y):将矩阵X中的每一个元素除以矩阵Y中对应的元素,返回值为Z
clear 
close all
clc
I=imread('coins.png');
subplot(221)
imshow(I)
title('原始图像')
background=imopen(I,strel('disk',15));
Ip=imdivide(I,background);
subplot(222)
imshow(Ip,[])
title('图像与背景相除')
J=imdivide(I,3);
subplot(223)
imshow(J)
title('图像与3相除的效果')
K=imdivide(I,0.6);
subplot(224)
imshow(K)
title('图像与0.6相除的效果')

Here Insert Picture Description

Guess you like

Origin www.cnblogs.com/xiegaosen/p/12011933.html