|
|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
& p$ L2 h/ _5 k, x. b% \; k! x4 C! l如果我们想在一幅图像上加上一个背景,那么我们可以将两幅做加法运算,在matlab中既可以使用imlincomb()函数,也可以使用imadd()函数。! j2 _5 D+ A8 n7 V
% @# s2 l2 [* I& L$ L+ ~/ ^: \close;0 F# g7 t$ [* [9 o* v
clear all;( f, f. L9 t+ W" |6 a( U" x' {
clc;) V* |- w0 _! b
A1 = imread('rice.png');
/ _+ ?% v G5 I/ g5 RA2 = imread('cameraman.tif');, N* i, T& a) q3 `3 g
K = imlincomb(0.5,A1,0.5,A2);% b( ?! E% e7 @3 d
subplot(1,3,1),subimage(A1);: t* h) B, f% I! T, D9 X g( F
title('原始图像1');
& d0 g3 w! ~! K( m9 vsubplot(1,3,2),subimage(A2);
/ b, p- U7 h% c7 jtitle('原始图像2');
0 F% l- k7 M+ a& Lsubplot(1,3,3),subimage(K);
, F' C }1 i7 Qtitle('0.5X图像1+0.5X图像2');. L% l4 ]* G3 L0 b* z1 r3 i# W
5 l8 q, \, M: a$ l
% Z+ w) N7 s! V/ L0 B
: K$ G0 h3 R* b$ d
改变两幅图像所占的比例:& x; l' P" E* x. t0 h1 x4 D
; P" l# R# m" T4 x第一幅仅占10%,第二幅占90%。
. [5 s0 H! b+ E% D4 X( Q. y
0 X7 K3 N: J1 a4 R$ |( l
& |( G, j: w; { j: f# ~" F
! }/ W0 m2 v0 x8 ~# }/ j$ f可以明显看到,第二幅图像更加明显。
3 B( \# m! j+ c" b- V
" `1 e4 f6 Z7 C3 n使用imadd()函数同样可以实现图像的加法运算;
0 a! g* c( W! s2 N/ ^
3 `& N) |) e' _+ P9 ?" E0 k) iclose;$ B3 V1 V, S- o6 H4 f$ d3 u
clear all;. c$ l) X, b7 [
clc;- i) Q6 w* y5 r1 `5 Y8 ^
A1 = imread('rice.png');
/ C5 Y& Y2 S4 }5 F; {( B, JA2 = imread('cameraman.tif');
/ H' C' ?& j* {6 ]8 {9 IK = imadd(A1,A2,'uint16');%图像相加,防止像素值超出255,因此把结果存为16位$ a) \# k, C6 `& ]
figure;
: Q4 W, ], D+ Y, c3 ?subplot(1,3,1);imshow(A1);title('rice原始图像');
0 ^! q6 W/ ^6 t' }5 W5 y% asubplot(1,3,2);imshow(A2);title('cameraman原始图像');
3 q. B$ o% p/ c& g2 B) Gsubplot(1,3,3);imshow(K,[]);title('相加图像');%注意使用imshow函数时,要加上[],以使得像素值压缩至0—255
& V$ `+ E7 x n1 ]9 U A( |0 T! _# D9 S6 l N9 m( d
( m( R# p7 _7 G& ^8 h) F0 a$ ~( [
( R& h0 X4 w' c+ F; m
|
|