-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathImgNormalize.m
33 lines (26 loc) · 977 Bytes
/
ImgNormalize.m
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
function normalizedImg = ImgNormalize(originalImg, method)
% Input:
% originalImg: origin image [data type: double or integer]
% method: if method == 1, histogram linear stretching; if method ==2, histogram nonlinear stertching
% Output: normalized image [data type: integer(uint8)]
% Author: Shuwei Xing
% Date: 2019-09-04
if nargin == 1
method = 1; % histogram linear stretch
end
switch method
case 1
originalImg = double(originalImg);
mappedMax = 255;
mappedMin = 0;
originalMax = max(max(originalImg));
%originalMin = min(min(originalImg)) % reduce the disturbtion from noise
originalMin = 0;
deltaOrigin = originalMax - originalMin;
scalar = (mappedMax - mappedMin)/deltaOrigin;
normalizedImg = (originalImg - originalMin) * scalar + mappedMin;
normalizedImg = uint8(normalizedImg);
case 2
disp('Undone!!')
end
end