-
Notifications
You must be signed in to change notification settings - Fork 0
/
hisread.asv
executable file
·68 lines (55 loc) · 1.81 KB
/
hisread.asv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
function img = hisread(file, frame, boolRotate)
%*******************************************************************************
% Read HIS Image
% hisread.m
%
% Purpose: To read an x-ray image HIS file from the PerkinElmer HIS
% file format. In XIS, all frames are saved in the HIS
% file. Since the desired image is usually only stored in
% one of these frames, one can specify the frame in which
% the image is contained.
%
% Author: Joey Carter
% Created: May 8, 2015
% Last Updated: May 11, 2015
%
%
% INPUT
%
% file: the .his file to be read in
% frame: the frame number in which the image is contained
% boolRotate: if true, image will be rotated counterclockwise by 90 deg
%
% OUTPUT
%
% img: the x-ray image
%
%*******************************************************************************
fid = fopen(file);
if fid == -1
warning('File could not be opened');
img = -1;
else
% Read in the entire .his file
hisFile = fread(fid, Inf, 'uint16')';
% Parse the header for image dimensions
header = hisFile(1:50);
dim = header(9:10);
% Number of pixels in one frame
nPixel = dim(1)*dim(2);
% Determine number of frames in .his file
nFrame = (length(hisFile) - length(header)) / nPixel;
if frame > nFrame
error('There are only %d frames in this file', nFrame)
end
% Read image from desired frame
start = (frame - 1) * nPixel + length(header) + 1;
finish = start + nPixel - 1;
img = hisFile(start:finish);
% Reshape array into rectangular matrix
img = reshape(img,dim)';
fclose(fid);
if boolRotate
img = rot90(img);
end
end