Professional Documents
Culture Documents
StartingMatlab
o CADELabremoteaccess
Studentversiononyourowncomputer
ChangetheCurrentFoldertothedirectorywhereyourprograms,images,etc.willbestored
GettinghelpfromMatlab(primers,tutorials,onlinehelp)
IfyouareaMatlabbeginneryoucanclickonGettingStartedforgeneralhelpwithhowMatlabworksor
clickonUser'sGuide|Programmingfundamentals|SyntaxBasicsforbasicinformationsuchashow
variablesarecreatedandinitializedinMatlab.
AnexcellentdescriptionofMatlabexpressionscanbefoundinGettingStarted|MatricesandArrays|
Expressions.ItpointsoutthefactthatMatlabstandsfor"MatrixLaboratory".Wheneverpossibleusea
matrixexpressioninsteadofaforlooptomakematrixcalculations.Theseexpressionswillexecute
muchfasterthannestedforloops,becauseMatlabisoptimizedformanipulatingmatrices.
Creating,writingandrunningprograms(mfiles)
o YoucanruncommandsintheCommandWindowtotryouthowtheywork
o Forautomaticallyrunningcommands,createanmfile.Thisisthe"sourcecode"forMatLabprograms.
mfilesareinterpretedprograms,calledscripts,andarenotcompiledbeforerunning.Remember:
Matlabisa"ComputationalProgram",notyourusualprogramminglanguage.
o mfilescanbecreatedintwoways:typeeditintheCommandwindoworclickontheActionsiconin
theCurrentFolderwindowandselectNewFile|Script:
TheEditorUntitledwindowwillpopup(whenyousaveityoucangiveitaname):
Ifyouwanttoprintyourscript,youcansetthepagelayouttoprintlinenumbersforreadability
Readingandwritingimages(matricesofpixeldata)
o typeimagesinSearchboxandclickonfirstresultlabeledasabasicMATLABfeatureavailablewithout
needingtheImageProcessingToolbox
readingimagesanddisplayingthem(notetheuseofthesemicolontosuppresscommandwindow
echo).Theseare3Dmatriceswhereeachpixelisa3elementvector:
image(rgb_img);
Convertcolortograyscale
o Findhelp:User'sGuide|Graphics|DisplayingBitmappedImages|Workingwith8Bitand16Bit
Images|Convertingan8BitRGBImagetoGrayscale
o Example:
1
2
3
4
5
6
7
8
9
10
11
12
13
Displayimages(multiple)
o figure,image,andsubplot
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
writingimages:
Datatypes(discrete,conversiontofloat)
o colorimagesare3Dmatrices,eachpixelbeinga3elementvectorwithintegerdatatypes(uint8or
uint16)
o imagesconvertedtograyscaleare2Dmatrices,eachpixelisanintegerwhichindexestoagrayscale
colormapwhenit'sdisplayed
o conversionofagrayscaleimagetosingleprecision,floatingpointvalue(single):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Command Window
Name
Size
I
Name
S
480x640
Size
480x640
Bytes
Class
307200
uint8
Bytes
Class
1228800
single
Attributes
Attributes
Readcursorpositionandvalues(manualdefinitionoffeatures)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Command Window
Click on the image to display a data tip, then press Return.
pos =
379
193
Overlaygrayscaleimagewithprocessedbinary(logicaldatatype)imageinformation(coloroverlay)
point operation:
Thresholdinganimage(binarize)withspecifiedthreshold.
Filtering:
Neighborhoodfilter:
o Averaging(smoothing)
o Edgedetection(x,yderivatives,magnitude>edgeimage)
o Application:overlaybinarizededgeimagewithoriginal