Importing Images
7
ReadtheimagedatafromthecurrentIFD(thesecondsubIFD)asyouwould
withanyotherIFDinthefile:
subimage_two = = t.read();
8
Viewthesecondsubimage:
imagesc(subimage_two)
9
Closethe
Tiff
object.
t.close();
2-107
Pdf page size limit - Compress reduce PDF size in C#.net, ASP.NET, MVC, Ajax, WinForms, WPF
C# Code & .NET API to Compress & Decompress PDF Document
pdf compression; compress pdf
Pdf page size limit - VB.NET PDF File Compress Library: Compress reduce PDF size in vb.net, ASP.NET, MVC, Ajax, WinForms, WPF
VB.NET PDF Document Compression and Decompression Control SDK
reader pdf reduce file size; best compression pdf
2
Importing Data
ImportingAudioandVideo
Inthis section...
“GettingInformationaboutAudioorVideoFiles”onpage2-108
“ReadingAudioFiles”onpage2-109
“RecordingandPlayingAudio”onpage2-109
“ReadingVideoFiles”onpage2-112
GettingInformationaboutAudioorVideoFiles
Togetinformationaboutfilesthatcontainaudiodata,videodata,orboth,use
mmfileinfo
.The
mmfileinfo
functionreturnstheduration,format,number
ofaudiochannels,andheightandwidthofvideo,asapplicable.
Togetmoreinformationaboutfilesthatcontainonlyvideodata,suchas
thenumberofframes,createamultimediaobjectwith
VideoReader
and
usethe
get
method.Formoreinformation,see“GettingInformationabout
VideoFiles”onpage2-113.
Characteristicsof AudioFiles
Theaudiosignalinafilerepresentsaseriesofsamplesthatcapturethe
amplitudeofthesoundovertime.Thesamplerateisthenumberofdiscrete
samplestakenpersecondandgiveninhertz. Theprecisionofthesamples,
measuredbythebitdepth(numberofbitspersample),dependsonthe
availableaudiohardware.
MATLABaudiofunctionsreadandstoresingle-channel(mono)audiodatain
an
m
-by-1columnvector,andstereodatainan
m
-by-2matrix.Ineithercase,
m
isthenumberofsamples.Forstereodata,thefirstcolumncontainstheleft
channel,andthesecondcolumncontainstherightchannel.
Typically,eachsampleisadouble-precisionvaluebetween-1and1.Insome
cases,particularlywhentheaudiohardwaredoesnotsupporthighbitdepths,
audiofilesstorethevaluesas8-bitor16-bitintegers.Therangeofthesample
valuesdependsontheavailablenumberofbits.Forexample,samplesstored
as
uint8
valuescanrangefrom0to255(2–1).TheMATLAB
sound
and
soundsc
functionssupportonlysingle-ordouble-precisionvaluesbetween
2-108
VB.NET PDF File Split Library: Split, seperate PDF into multiple
PDF document file to one-page PDF files or As String = Program.RootPath + "\\" 1.pdf" ' set split SplitOptions(SplitMode.BySize) ' limit the size of each
.pdf printing in thumbnail size; adjusting page size in pdf
C# PDF File Split Library: Split, seperate PDF into multiple files
options = new SplitOptions(SplitMode.BySize); //limit the size of each String inputFilePath = Program.RootPath + "\\" source.pdf"; //Page indexes to
adjust size of pdf file; pdf file size limit
ImportingAudioandVideo
-1and1.Otheraudiofunctionssupportmultipledatatypes,asindicatedon
thefunctionreferencepages.
ReadingAudioFiles
TheeasiestwaytoreadaudiodatafromafileistousetheImportWizard,
agraphicaluserinterface. TheImportWizardcanreadWAV,AU,orSND
files.TostarttheImportWizard,selectFile>ImportDataordouble-click
thefilenameintheCurrentFolderbrowser. ToimportWAVfileswithout
invokingagraphicaluserinterface,use
wavread
.
RecordingandPlayingAudio
Thissectiondiscussesthefollowingtopics:
• “RecordingAudio”onpage2-109
• “PlayingAudio”onpage2-110
• “RecordingorPlayingAudiowithinaFunction”onpage2-111
RecordingAudio
Torecorddatafromanaudioinputdevice(suchasamicrophoneconnectedto
yoursystem)forprocessinginMATLAB:
1
Createan
audiorecorder
object.
2
Callthe
record
or
recordblocking
method,where:
record
returnsimmediatecontroltothecallingfunctionorthecommand
promptevenasrecordingproceeds.Specifythelengthoftherecording
inseconds,orendtherecordingwiththe
stop
method.Optionally,call
the
pause
and
resume
methods.
recordblocking
retainscontroluntiltherecordingiscomplete.Specify
thelengthoftherecordinginseconds.
3
Createanumericarraycorrespondingtothesignaldatausingthe
getaudiodata
method.
2-109
C# PowerPoint: How to Set PowerPoint Rendering Parameters in C#
2007 or above) slide into PDF document or other rendering process if the slide/page is too REImage CropImage(Rectangle sourceRegion, Size targetSize); Bitmap
pdf text box font size; change font size in pdf comment box
C# Excel: Customize Excel Conversion by Setting Rendering Options
0, (int)(originalWidth), (int)(originalHeight / 2)), new Size((int)(originalWidth the top half of Excel page to image to these file formats, like PDF, TIFF, SVG
can a pdf be compressed; best online pdf compressor
2
Importing Data
Forexample,connectamicrophonetoyoursystemandrecordyourvoicefor5
seconds.Capturethenumericsignaldataandcreateaplot:
% Record d your voice for 5 seconds.
recObj = audiorecorder;
disp('Start speaking.')
recordblocking(recObj, 5);
disp('End of f Recording.');
% Play y back the recording.
play(recObj);
% Store e data in double-precision array.
myRecording = getaudiodata(recObj);
% Plot t the samples.
plot(myRecording);
SpecifyingtheQualityoftheRecording. Bydefault,an
audiorecorder
objectusesasamplerateof8000hertz,adepthof8bits(8bitspersample),
andasingleaudiochannel.Thesesettingsminimizetherequiredamount
ofdatastorage.Forhigherqualityrecordings,increasethesamplerateor
bitdepth.
Forexample,typicalcompactdisksuseasamplerateof44,100hertzand
a16-bitdepth. Createan
audiorecorder
objecttorecordinstereo(two
channels)withthosesettings:
myRecObj = audiorecorder(44100, 16, , 2);
Formoreinformationontheavailablepropertiesandvalues,seethe
audiorecorder
referencepage.
PlayingAudio
Afteryouimportorrecordaudio,MATLABsupportsseveralwaystolisten
tothedata:
• Forsimpleplaybackusingasinglefunctioncall,use
sound
or
soundsc
.
Forexample,loadademoMAT-filethatcontainssignalandsamplerate
data,andlistentotheaudio:
2-110
VB.NET Excel: VB Methods to Set and Customize Excel Rendering
treat every single Excel spreadsheet as a page in our the fixed image size ration that the size is limited Excel to other document files, like PDF with online
pdf font size change; pdf page size
ImportingAudioandVideo
load chirp.mat;
sound(y, Fs);
• Formoreflexibilityduringplayback,includingtheabilitytopause,resume,
ordefinecallbacks,usethe
audioplayer
function.Createan
audioplayer
object,thencallmethodstoplaytheaudio. Forexample,listentothe
gong
demo:
load gong.mat;
gong = = audioplayer(y, Fs);
play(gong);
Foranadditionalexample,see“RecordingorPlayingAudiowithina
Function”onpage2-111.
Ifyoudonotspecifythesamplerate,
sound
playsbackat8192hertz.Forany
playback,specifysmallersampleratestoplaybackmoreslowly,andlarger
sampleratestoplaybackmorequickly.
Note Mostsoundcardssupportsampleratesbetweenapproximately5,000
and48,000hertz. Specifyingsampleratesoutsidethisrangecanproduce
unexpectedresults.
RecordingorPlayingAudiowithinaFunction
Unlikegraphicshandles,ifyoucreatean
audioplayer
or
audiorecorder
objectinsideafunction,theobjectexistsonlyforthedurationofthefunction.
Forexample,createaplayerfunctioncalled
playFile
andasimplecallback
function
showSeconds
:
function playFile(myfile)
load(myfile);
obj = audioplayer(y, Fs);
obj.TimerFcn = = 'showSeconds';
obj.TimerPeriod = 1;
play(obj);
end
2-111
2
Importing Data
function showSeconds
disp('tick')
end
Call
playFile
fromthecommandprompttoplaythedemofile
handel.mat
:
playFile('handel.mat')
Attherecordedsamplerateof8192samplespersecond,playingthe73113
samplesinthefiletakesapproximately8.9seconds.However,the
playFile
functiontypicallyendsbeforeplaybackcompletes,andclearsthe
audioplayer
object
obj
.
Toensurecompleteplaybackorrecording,considerthefollowingoptions:
• Use
playblocking
or
recordblocking
insteadof
play
or
record
. The
blockingmethodsretaincontroluntilplayingorrecordingcompletes.Ifyou
blockcontrol,youcannotissueanyothercommandsormethods(suchas
pause
or
resume
)duringtheplaybackorrecording.
• Createanoutputargumentforyourfunctionthatgeneratesanobjectin
thebaseworkspace.Forexample,modifythe
playFile
functiontoinclude
anoutputargument:
function obj = = playFile(myfile)
Callthefunction:
h = = playFile('handel.mat');
Because
h
existsinthebaseworkspace,youcanpauseplaybackfromthe
commandprompt:
pause(h)
ReadingVideoFiles
Toimportvideodatafromafile,constructareaderobjectwith
VideoReader
andreadselectedframeswiththe
read
function.
Forexample,importallframesinthedemofile
xylophone.mpg
:
2-112
ImportingAudioandVideo
xyloObj = = VideoReader('xylophone.mpg');
vidFrames = = read(xyloObj);
Itisnotnecessarytoclosethemultimediaobject.
Formoreinformation,see:
• “GettingInformationaboutVideoFiles”onpage2-113
• “ProcessingFramesofaVideoFile”onpage2-114
• “ReadingVariableFrameRateVideo”onpage2-115
• “SupportedVideoFileFormats”onpage2-116
GettingInformation aboutVideoFiles
VideoReader
createsanobjectthatcontainspropertiesofthevideofile,
includingtheduration,framerate,format,height,andwidth.Toviewthese
properties,orstoretheminastructure,usethe
get
method. Forexample,
getthepropertiesofthedemofile
xylophone.mpg
:
xyloObj = = VideoReader('xylophone.mpg');
info = = get(xyloObj)
The
get
functionreturns:
info =
Duration: 4.7020
Name: 'xylophone.mpg'
Path: [1x75 char]
Tag: ''
Type: 'VideoReader'
UserData: []
BitsPerPixel: 24
FrameRate: 29.9700
Height: 240
NumberOfFrames: 141
VideoFormat: 'RGB24'
Width: 320
2-113
2
Importing Data
Toaccessaspecificpropertyoftheobject,suchas
Duration
,usedotnotation
asfollows:
duration = xyloObj.Duration;
Note Forfileswithavariableframerate,
VideoReader
cannotreturn
thenumberofframesuntilyoureadthelastframeofthefile. Formore
information,see“ReadingVariableFrameRateVideo”onpage2-115.
ProcessingFramesofaVideoFile
Atypicalvideocontainsmanyframes.Tosavememory,processavideoone
frameatatime.Forfasterprocessing,preallocatememorytostorethevideo
data.
Forexample,convertthedemofile
xylophone.mpg
toaMATLABmovie,
andplayitwiththe
movie
function:
xyloObj = = VideoReader('xylophone.mpg');
nFrames = = xyloObj.NumberOfFrames;
vidHeight = = xyloObj.Height;
vidWidth = xyloObj.Width;
% Preallocate e movie structure.
mov(1:nFrames) = = ...
struct('cdata', zeros(vidHeight, vidWidth, , 3, , 'uint8'),...
'colormap', []);
% Read d one frame at a time.
for k = 1 1 : : nFrames
mov(k).cdata = read(xyloObj, k);
end
% Play y back the movie once at the video's frame rate.
movie(mov, 1, xyloObj.FrameRate);
2-114
ImportingAudioandVideo
ReadingVariableFrameRateVideo
Somefilesstorevideoatavariableframerate,includingmanyWindows
MediaVideofiles.Forthesefiles,
VideoReader
cannotdeterminethenumber
offramesuntilyoureadthelastframe.
Forexample,considerahypotheticalfile
VarFrameRate.wmv
thathasa
variableframerate. Acallto
VideoReader
tocreatethemultimediaobject
suchas
obj = VideoReader('VarFrameRate.wmv')
returnsthefollowingwarningandsummaryinformation:
Warning: Unable to determine the number of frames in this file.
Summary of Multimedia Reader Object t for r 'VarFrameRate.wmv'.
Video Parameters:
23.98 frames per second, RGB24 4 1280x720.
Unable to determine video o frames available.
CountingFrames. Todeterminethenumberofframesinavariableframe
ratefile,call
read
withthefollowingsyntax:
lastFrame = read(obj, inf);
Thiscommandreadsthelastframeandsetsthe
NumberOfFrames
propertyof
themultimediaobject.Because
VideoReader
mustdecodeallvideodatato
counttheframesreliably,thecallto
read
sometimestakesalongtimetorun.
SpecifyingtheFramestoRead. Foranyvideofile,youcanspecifythe
framestoreadwitharangeofindices.Usually,ifyourequestaframebeyond
theendofthefile,
read
returnsanerror.
However,ifthefileusesavariableframerate,andtherequestedrange
straddlestheendofthefile,
read
returnsapartialresult.Forexample,given
afilewith2825framesassociatedwiththemultimediaobject
obj
,acallto
readframes2800-3000asfollows:
images = read(obj, [2800 3000]);
returns:
2-115
2
Importing Data
Warning: The end of file was reached before e the
requested frames s were read completely.
Frames 2800 through 2825 were returned.
SupportedVideoFileFormats
The
VideoReader
functionreferencepagelistsfileformatsthat
VideoReader
usuallycanread,includingAVI,MPEG-1,andMotionJPEG2000.Sometimes
VideoReader
canreadfilesinunlistedformats,andsometimesitcannot
readfilesinlistedformats.
Forvideodata,theterm“fileformat”oftenreferseithertothecontainer
formatorthecodec.Acontainerformatdescribesthelayoutofthefile,whilea
codecdescribeshowtocode/decodethedata.Manycontainerformatssupport
multiplecodecs.
Toreadavideofile,anyapplicationmust:
• Recognizethecontainerformat(suchasAVI).The
VideoReader
function
referencepageliststhesupportedcontainerformats.
• Haveaccesstothecodecassociatedwiththeparticularfile.Somecodecsare
partofstandardWindowsandMacintoshsysteminstallations,andallow
youtoplayvideoinWindowsMediaPlayerorQuickTime.
VideoReader
canaccessmost,butnotall,ofthesecodecs.
• Properlyinterpretthecodec.
VideoReader
cannotalwaysreadfiles
associatedwithcodecsthatwerenotpartofyouroriginalsystem
installation.
Toseethecodecassociatedwithavideofile,use
mmfileinfo
andviewthe
Format
field.Forexample,givenahypotheticalAVIfilethatusestheIndeo®
5codec,thefollowingcode:
info = = mmfileinfo('myfile.avi');
info.Video.Format
returns
ans =
IV50
2-116
Documents you may be interested
Documents you may be interested