Các hàm xử lý ảnh trong matlab

  • Published on
    18-Feb-2015

  • View
    613

  • Download
    10

Embed Size (px)

DESCRIPTION

xu ly anh matlab

Transcript

27/03/2013

Cc hm x l nh trong matlabUserNameRemember Me

Login

Forgot password? || Register !Viet Nam

English

HOME Trang Ch DANH MUC SAN PHAM Shop Development Kit Peripheral Modules ROBOCON Equipments Programmer/Debugger Education Robot Products DC Servo Motor Ph kin - Spare part All

PRODUCTS

R&D LABS Nghin Cu

VIDEO DEMO H-Lab On Youtube

CONTACT Lin H

Cc hm x l nh trong matlabSATURDAY, 13 AUGUST 2011 17:02 ADMINISTRATOR

14 likesThere are no translations available.

2 dislikes

Trong phn ny chng ta s tm hiu v cc hm x l nh trong matlab. Nh chng ta bit, matlab l mt ngn ng rt mnh v h tr rt tt cc thao tc lm vic trn nh. V vy vic s dng matlab cho cc ng dng x l nh gn nh l la chn hng u cho nhng ai mun thc hin cc thut ton x l trn phn mm.

Xem Ph n 1 : Gii thi u v matlab v x l nhCc kiu nh trong Matlab

R&D LABS FPGA/ASIC RESEARCH DSP RESEARCH MCU APPLICATION EMBEDDED SYSTEM AUTOMATIC SYSTEMS SUPPORT ROBOCON BASIC MCU/DSP/FPGA NGHIN CU / TI DOCUMENT DOWNLOAD COMMENT LATEST file testbench vit ring. fi... Anh i, my code ny u gp t... Minh da updated lai roi nha ad lam on check lai link nhe, ... sao minh download ko dc vay ??

a) nh c nh ch s (Indexed Images) Mt nh ch s bao gm mt ma trn d liu X v ma trn bn mu map. Ma trn d liu c th c kiu thuc lp uint8, uint16 hoc kiu double. Ma trn bn mu l mt mng mx3 kiu double bao gm cc gi tr du phy ng nm gia 0 v 1. Mi hng ca bn ch ra cc gi tr m: red, green v blue ca mt mu n. Mt nh ch s s dng nh x trc tip gia gi tr ca pixel nh ti gi tr trong bn mu. Mu sc ca mi pixel nh c tnh ton bng cch s dng gi tr tng ng ca X nh x ti mt gi tr ch s ca map. Gi tr 1 ch ra hng u tin, gi tr 2 ch ra hng th hai trong bn mu Mt bn mu thng c cha cng vi nh ch s v c t ng np cng vi nh khi s dng hm imread c nh. Tuy nhin, ta khng b gii hn khi s dng bn mu mc nh, ta c th s dng bt k bn mu no. b) nh cng (Intensity Images) Mt nh cng l mt ma trn d liu nh I m gi tr ca n i din cho cng trong mt s vng no ca nh. Matlab cha mt nh cng nh mt ma trn n, vi mi phn t ca ma trn tng ng vi mt pixel ca nh. Ma trn c th thuc lp double, uint8 hay uint16. Trong khi nh cng him khi c lu vi bn mu, Matlab s dng bn mu hin th chng. Nhng phn t trong ma trn cng i din cho cc cng khc nhau hoc xm. Nhng im c cng bng 0 thng c i din bng mu en v cng 1,255 hoc 65535 thng i din cho cng cao nht hay mu trng. c) nh nh phn (Binary Images) Trong mt nh nh phn, mi pixel ch c th cha mt trong hai gi tr nh phn 0 hoc 1. Hai gi tr ny tng ng vi bt hoc tt (on hoc off). Mt nh nh phn c lu tr nh mt mng logic ca 0 v 1. d) nh RGB (RGB Images) Mt nh RGB - thng c gi l true-color, c lu tr trong Matlab di dng mt mng d liu c kch thc 3 chiu mxnx3 nh ngha cc gi tr mu red, green v blue cho mi pixel ring bit. nh RGB khng s dng palette. Mu ca mi pixel c quyt nh bi s kt hp gia cc gi tr R, G, B (Red, Green, Blue) c lu tr trong mt mt phng mu ti v tr ca pixel. nh dng file ho lu tr nh RGB ging nh mt nh 24 bits trong R, G, B chim tng ng 8 bit mt. iu ny cho php nhn c 16 triu mu khc nhau. Mt mng RGB c th thuc lp double, uint8 hoc uint16. Trong mt mng RGB thuc lp double, mi thnh phn mu c gi tr gia 0 v 1. Mt pixel m thnh phn mu ca n l (0, 0, 0) c hin th vi mu en v mt pixel m thnh phn mu l (1, 1, 1 ) c hin th vi mu trng. Ba thnh phn mu ca mi pixel c lu tr cng vi chiu th 3 ca mng d liu. Chng hn, gi tr mu R, G, B ca pixel (10, 5) c lu tr trong RGB(10, 5, 1), RGB(10, 5, 2) v RGB(10, 5, 3) tng ng. tnh ton mu sc ca pixel ti hng 2 v ct 3 chng hn, ta nhn vo b ba gi tr c lu tr trong (2, 3, 1:3). Gi s (2, 3, 1) cha gi tr 0.5176; (2, 3, 2) cha gi tr 0.1608 v (2, 3, 3) cha gi tr 0.0627 th mu sc ca pixel ti (2, 3) s l (0.5176, 0.1608, 0.0627).

Cc hm x l nh c bn trong Matlaba) c v ghi d liu nh c mt nh ho - Hm imread c mt nh t bt k nh dng no c tr gip trong bt k chiu su bit no c tr gip. Hu ht cc file nh s dng 8 bit cha gi tr ca pixel. Khi chng c c vo b nh, Matlab cha chng di dng uint8. Vi cc file tr gip 16 bt d liu, PNG v TIFF, Matlab cha chng di dng uint16. Ch : Vi nh ch s, imread lun lun c bn mu vo trong mt chui thuc lp double, thm ch mng nh t n thuc lp uint8 hay uint16 - Chng hn, on m sau s c mt nh RGB vo khng gian lm vic ca Matlab lu trong bin RGB.

hlab.com.vn/index.php?option=com_content&view=article&id=202%3Ax-ly-nh-vi-matlab&catid=47%3Ac-bn-v-dsp&Itemid=113&lang=en

1/13

27/03/2013R G B = i m r e a d ( f o o t b a l l . j p g ) ;

Cc hm x l nh trong matlab

Trong v d ny, imread s nhn ra nh dng file s dng t tn file. Ta cng c th ch ra nh dng file nh mt tham s trong hm imread. Matlab tr gip rt nhiu nh dng ho thng dng chng hn: BMP, GIF, JPEG, PNG, TIFF bit thm cc kiu gi hm v tham s truyn vo, xem tr gip online ca Matlab. c nhiu nh t mt file ho - Matlab tr gip mt s nh dng file ho chng hn nh: HDF v TIFF, chng cha nhiu nh. Theo mc nh, imread ch tr gip nh u tin trong file. nhp thm cc nh t file, s dng c php c tr gip bi nh dng file. Chng hn, khi c s dng vi TIFF, ta c th s dng mt gi tr ch s vi imread ch ra nh m ta mun nhp vo. V d sau y c mt chui 27 nh t mt file TIFF v lu nhng nh ny trong mt mng 4 chiu. Ta c th s dng hm iminfo xem bao nhiu nh c lu tr trong file: m r i=u i n t 8 ( z e r o s ( 1 2 8 , 1 2 8 , 1 , 2 7 ) ) ;%p r e a l l o c a t e4 Da r r a y f o rf r a m e = 1 : 2 7 [ m r i ( : , : , : , f r a m e ) , m a p ]=i m r e a d ( ' m r i . t i f ' , f r a m e ) ; E n d

- Khi file cha nhiu nh theo mt s kiu nht nh chng hn theo th t thi gian, ta c th lu nh trong Matlab di dng mng 4 chiu. Tt c cc nh phi c cng kch thc. Ghi mt nh ho - Hm imwrite s ghi mt nh ti mt file ho di mt trong cc nh dng c tr gip. Cu trc c bn nht ca imwrite s yu cu mt bin nh v tn file. Nu ta gp mt phn m rng trong tn file, Matlab s nhn ra nh dng mong mun t n. V d sau ti mt nh ch s X t mt file Map vi bn mu kt hp vi n map sau ghi nh xung mt file bitmap. l o a dc l o w n w h o s N a m e S i z e X 2 0 0 x 3 2 0 c a p t i o n 2 x 1

B y t e s C l a s s 5 1 2 0 0 0 d o u b l ea r r a y 4 c h a ra r r a y

m a p 8 1 x 3 1 9 4 4 d o u b l ea r r a y G r a n dt o t a li s6 4 2 4 5e l e m e n t su s i n g5 1 3 9 4 8b y t e s i m w r i t e ( X , m a p , ' c l o w n . b m p ' )

Ch ra nh dng ph - Tham s c bit - Khi s dng imwrite vi mt s nh dng ho, ta c th ch ra cc tham s ph. Chng hn, vi nh dng PNG ta c th ch ra su bit nh mt tham s ph. V d sau s chi mt nh cng I vi mt file nh 4 bit PNG. i m w r i t e ( I , ' c l o w n . p n g ' , ' B i t D e p t h ' , 4) ; H-LAB ON YOUTUBE

- bit thm cc cu trc khc ca hm xem phn tr gip trc tuyn ca Matlab. c v ghi nh nh phn theo nh dng 1 bit - Trong mt s nh dng file, mt nh nh phn c th c lu trong mt nh dng 1 bit. Nu nh dng file tr gip n, Matlab ghi nh nh phn nh nh 1 bit theo mc nh. Khi ta c mt nh nh phn vi nh dng 1 bit, Matlab i din n trong khng gian lm vic nh mt mng lgic. - V d sau c mt nh nh phn v ghi n di dng file TIFF. Bi v nh dng TIFF tr gip nh 1 bit, file c ghi ln a theo nh dng 1 bit: B W=i m r e a d ( ' t e x t . p n g ' ) ; i m w r i t e ( B W , ' t e s t . t i f ' ) ;

VISITOR COUNTER

kim tra chiu su bit ca file test.tif, gi hm iminfo v kim tra trng BitDepth ca n: i n f o=i m f i n f o ( ' t e s t . t i f ' ) ; i n f o . B i t D e p t h a n s= 1

Hm nay Hm qua Thng ny Tt c

2988 5480 172206 197974

Ch : Khi ghi file nh phn, Matlab thit lp trng ColorType thnh grayscale. Xem lp lu tr ca file - Hm imwrite s dng lut sau y quyt nh lp lu tr c s dng trong nh kt qu: + logical: Nu nh dng nh ra (Output Image) c ch r l tr gip nh 1 bit, hm imwrite to mt file nh 1 bit. Nu nh dng nh ra c ch r l khng tr gip nh 1 bit (nh JPEG), hm imwrite chuyn nh ti mt nh thuc lp uint8. + uint8: Nu nh dng nh ra c ch r l tr gip nh 8 bit, hm imwrite to mt nh 8 bit

We have: 28 guests online Chrome 25.0.1364.172, Windows Hm nay: Mar 27, 2013 Visitors Counter

hlab.com.vn/index.php?option=com_content&view=article&id=202%3Ax-ly-nh-vi-matlab&catid=47%3Ac-bn-v-dsp&Itemid=113&lang=en

2/13

27/03/2013

Cc hm x l nh trong matlab+ uint16: Nu nh dng nh ra c ch r tr gip nh 16 bit (PNG hoc TIFF), hm imwrite to mt nh 16 bit. Nu nh dng nh ra khng tr gip nh 16 bit, hm chuyn i d liu nh ti lp uint8 v to mt nh 8 bit. + double: Matlab chuyn d liu nh ti dng uint8 v to mt nh 8 bit bi v hu ht cc file nh s dng nh dng 8 bit. Truy vn mt file ho - Hm imfinfo cho php ta c th nhn c thng tin v mt file nh c tr gip bi toolbox. C php: imfinfo(filename,fmt) Cc thng tin c cung cp bi hm imfinfo l: filename, filemodedate, filesize, format, formatversion, width, height, bitdepth, colortype Thng tin m ta nhn c ph thuc vo kiu ca file nhng n lun bao gm nhng thng tin sau:

Tn ca file nh. nh dng file nh. S version ca nh dng file. Ngy sa i file gn nht. Kch thc file tnh theo byte.AI ANG ONLINE Now online: 25 guests Latest members: xlhwbqvom Nguyen Trung Thanh

Chiu rng nh tnh theo pixel. Chiu cao nh tnh theo pixel. S lng bt trn mt pixel. Kiu nh: RGB, ch s b) Hin th nh Dng hm imview - hin th mt nh s dng hm imview, dng hm imview, ch r nh m ta mun hin th. Ta c th s dng imview hin th mt nh m c nhp vo trong khng gian lm vic ca Matlab. m o o n f i g=i m r e a d ( ' m o o n . t i f ' ) ; i m v i e w ( m o o n f i g ) ;

Total members: 1527 RSS

Ta cng c th ch nh tn ca file nh nh trong v d sau: Feed Entries imview('moon.tif');

- File nh phi c mt trong th mc hin ti hoc trong ng dn ca Matlab. C u trc ny c th hu ch cho vic qut qua nhiu nh. Tuy nhin, lu , khi s dng cu trc ny, d liu nh khng c lu trong khng gian lm vic ca Matlab. - Nu ta gi hm imview m khng ch ra mt k tham s no, n s hin th mt hp chn file cho php ta ch ra tn file mun hin th. Xem nhiu nh - Nu ta ch ra mt file m cha nhiu nh, hm imview ch hin th nh u tin trong file . xem tt c cc nh trong file, s dng hm imread nhp mi nh vo trong khng gian