1 | %'read_image': read images or video objects |
---|
2 | %---------------------------------------------------------------------- |
---|
3 | % function [A,ObjectOut]=read_image(FileName,FileType,VideoObject,num) |
---|
4 | % |
---|
5 | % OUTPUT: |
---|
6 | % A(npy,npx,rgb): matrix of integers (iunt8 or uint16) representing the image, with sizes npy, npx, and possibly color component rgb=1:3 |
---|
7 | % ObjectOut: video object (=[] for single images) |
---|
8 | % |
---|
9 | % INPUT: |
---|
10 | % FileName: input file name |
---|
11 | % other inputs needed only for video and multi-image file: |
---|
12 | % FileType: input file type, as determined by the function get_file_info.m |
---|
13 | % VideoObject: video object (for faster reading if availlable) |
---|
14 | % num: frame index for movies or multimage types |
---|
15 | % |
---|
16 | function [A,ObjectOut]=read_image(FileName,FileType,VideoObject,num) |
---|
17 | %----------------------------------------------------------------------- |
---|
18 | if ~exist('FileType','var') |
---|
19 | FileType='image'; |
---|
20 | end |
---|
21 | if ~exist('VideoObject','var') |
---|
22 | VideoObject=[]; |
---|
23 | end |
---|
24 | if ~exist('num','var') |
---|
25 | num=1; |
---|
26 | end |
---|
27 | ObjectOut=VideoObject;%default |
---|
28 | switch FileType |
---|
29 | case 'video' |
---|
30 | if strcmp(class(VideoObject),'VideoReader') |
---|
31 | A=read(VideoObject,num); |
---|
32 | else |
---|
33 | ObjectOut=VideoReader(FileName); |
---|
34 | A=read(ObjectOut,num); |
---|
35 | end |
---|
36 | case 'mmreader' |
---|
37 | if strcmp(class(VideoObject),'mmreader') |
---|
38 | A=read(VideoObject,num); |
---|
39 | else |
---|
40 | ObjectOut=mmreader(FileName); |
---|
41 | A=read(ObjectOut,num); |
---|
42 | end |
---|
43 | case 'multimage' |
---|
44 | A=imread(FileName,num); |
---|
45 | case 'image' |
---|
46 | A=imread(FileName); |
---|
47 | end |
---|