-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwindowImage.m
More file actions
27 lines (22 loc) · 805 Bytes
/
Copy pathwindowImage.m
File metadata and controls
27 lines (22 loc) · 805 Bytes
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
function wImage = windowImage( iImage, iCenter, iWidth, iOutputDynamicRange )
%WINDOWIMAGE grayscale windowing of an image
% function [ output_args ] = windowImage( iImage, iCenter, iWidth)
% performs grayscale windowing to a 0:255 output range
%
% function [ output_args ] = windowImage( iImage, iCenter, iWidth, iOutputDynamicRange )
% performs grayscale windowing to arbitrary range format: [ low high]
%% parse input
if nargin<4
iOutputDynamicRange=[0 255];
end
%% Set lo and hi
outlo=min(iOutputDynamicRange);
outhi=max(iOutputDynamicRange);
lo=iCenter-iWidth/2;
hi=iCenter+iWidth/2;
wImage=NaN(size(iImage));
wImage(iImage<=lo)=outlo;
wImage(iImage>hi-1)=outhi;
%% Window
wImage(isnan(wImage))=((outhi-outlo+1)/iWidth)*(iImage(isnan(wImage))-lo)+outlo;
end