|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
$ i2 F- } J2 @. rMatlab里面显示一张图片的话,长宽比取决于图片的横向纵向像素点数。
* n- a3 ` u+ O# U- P; X! e如果一张图片是433×433的话,那么imshow之后,就会按1比1比例显示,即使你拉伸窗口。
; P% w# f( M* @
; g" Y. U- b: d: u* Efname = 'frog.bmp';9 W5 B6 R- h4 w, p* B
A=imread(fname);! ^! c: R2 u* c% `
imshow(A);- d9 V9 k! X8 x% ^6 q5 d
set(gcf,'position',[100 100 400 800]);
" X. S% D) s# a7 s- f( j4 i, J/ o; N效果如下:
# T1 N) C8 i" m# g; u9 D$ X1 I Y
* a' k' w/ P5 g5 y8 }
+ j6 b5 `- Y; S+ P8 M# S
3 D4 |9 v: R; O- ]4 t, ~' d怎么能让图片充满整个画框呢。可以用画图板打开,拉伸图片,然后重新保存。6 C$ d8 b) y+ r! A3 Y' P
或者写个函数. k- a' P2 C' P$ N7 Y+ F, C+ [4 e
; ~ l9 _ M$ ?B= figure_stretch(A,1,3);
8 \3 G1 f. d. S" \* E0 z. Ufigure! N5 b$ a* E8 d2 [0 A+ e" _: C
imshow(B);- d: t% Y0 |( W; @8 Q
set(gcf,'position',[100 100 400 800]);
+ Y1 P, j; F+ m* \- Z5 a% F9 l+ o1 a/ b; i; f! X
效果如下:
3 u& q9 T. O1 p8 x
( E/ l0 ?- z) t4 K) [
( p' g* [% Q% e9 o
1 s. A! S& I$ v2 t0 [- t
figure_stretch函数如下:
) k7 ?% T4 P' W, `7 rfunction C=figure_stretch(fname,w_scale,h_scale)
$ @/ ]0 h9 B3 C% Stretch the figure.9 ?' ]2 G5 u5 G9 l _4 i2 V) j
% Usage:. w% ^% ?; w- i8 j7 z. S! G/ ` |
% C=figure_stretch(fname,w_scale,h_scale)
* G9 D" H% @- K/ s$ K3 G+ p, P% fname : name of the figure
- ^; W% @: O$ R* g1 T% w_scale : stretch scale in width
3 j7 v; x! z3 Y" v, Z; t& X% h_scale : stretch scale in hight, m, e" G! D! u5 j
% Example:
s8 z: [1 V( n6 h+ y: n( H% fname = 'frog.bmp';" N( }' }' i2 V0 w
% B= B= figure_stretch(fname,1,3);) ^! [" B& Q* e" w% f
% figure
* W+ R5 T% s" c% [6 A% imshow(B);
+ M0 l* ~: I/ V% Author : Haiyang Cui* w$ {3 P5 t3 S% ?
% EMail : ***
. F! d3 B6 g2 U. _' h4 I3 j) t- N' e
A= imread(fname);- h; q& W' y+ W1 n2 B$ F1 @& x
[I,J,K]=size(A);
# e% E! i* {( g, Y- ~- ^% e* t( qx0=1:J;6 S& g. V- I. ]7 m% H
y0=1:I;4 j/ v5 ?" O. C0 l8 l, O, ~
[X0,Y0] = meshgrid(x0,y0);
0 V5 ?3 e% Y8 i/ JI1 = floor(I*h_scale);" s+ ]/ Y- T/ a3 X8 R
J1 = floor(J*w_scale);
; l' g% l2 u& G! `& \9 }( Z
' `+ ]% w3 c7 f6 vR = A(:,:,1);7 G$ E; R' A) p' Y
G = A(:,:,2);
: ~$ n/ ^: Z k9 B% gB = A(:,:,3);
; K9 {: { }* B I; Y2 [2 E- `+ R( s/ r: B6 t# U; R3 t
%
# Z; K' f' _% R, X: _x = 1:J1;" P9 v+ G( T5 T, |8 n& q8 r: x4 f
y = 1:I1;
# w& A7 H/ n- @: I( N h0 `0 V& l( p$ D[X,Y] = meshgrid(x,y);
1 r% F% _, Q5 ?* T# K5 K8 j+ O8 T _3 a: F+ x- n6 t& B
X = X*J/J1;/ h3 L1 Q7 U7 ^3 a
Y = Y*I/I1;
4 v5 L+ F8 l6 O) M$ Z; C" E$ T" {X = double(X);+ h7 c( F+ U' o
Y = double(Y);' u4 {( F8 R0 u% D/ w$ v7 {; z
R = double(R);
; m5 A4 ?+ M6 P. g4 T8 S9 lG = double(G);3 T* g2 J! W" C' C
B = double(B);
- j5 G5 L8 I7 e) P7 E$ m; a' a%
# ~1 c8 E3 u0 o0 i0 Z5 sR1 = interp2(X0,Y0,R,X,Y);0 P# D8 @, Q; P* Q* x
G1 = interp2(X0,Y0,G,X,Y);
) S& k: |1 r0 vB1 = interp2(X0,Y0,B,X,Y);
R" H2 J6 D% i, Y/ RC(:,:,1)=uint8(R1);
% l/ ^8 t. j" {# IC(:,:,2)=uint8(G1);
5 h+ d/ t$ i8 [+ q& ?' UC(:,:,3)=uint8(B1);
" ]7 D! c/ h, {9 b" mend
& {% s7 W1 W+ N, b' i# r8 ~8 X1 _
. r/ }4 j4 M9 x. c! \$ m |
|