Tuesday, December 1, 2015

Matlab: Recognizing the Valid Range

Summary

代码识别影像有效数值区间,并显示有效数值之数量。

Code Specification

配置igValues忽略数值,输出有效数值数量及范围如Fig. 1。
Fig. 1
 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
% Created by LI Xu
% Version 1.0
% December 2, 2015

% Description:
% Recognize the valid range for the input image

% If you have any question about this code,
% please do not hesitate to contact me via E-mail: 
% jeremy456@163.com

% Blog:
% http://blog.sciencenet.cn/u/lixujeremy
% http://lixuworld.blogspot.com/

clear;
clc;

% Values for Ingnoring
igValues=[-99, 100];
% Source Directory
SouDir='./input';
% All files
files=dir([SouDir, '/*.tif']);
% Loop
for ii=1:length(files)
    filename=files(ii).name;
    filepath=[SouDir, '/', filename];
    image=imread(filepath);
    data=image;
    imgsz=size(data);
    num=imgsz(1)*imgsz(2);
    data=reshape(data, 1, num);
    for jj=1:length(igValues)
        igV=igValues(jj);
        index=find(data==igV);
        if isempty(index)
            continue;
        end
        data(index)=[];       
    end
    
    % Max
    max_data=max(data);
    % Min
    min_data=min(data);
    % Display
    fprintf('%d-%s-%d: ', ii, filename, length(data));
    fprintf('%.5f~%.5f\n', min_data, max_data);
    
end

disp('*********************************************');

No comments:

Post a Comment