a b/Image features calculation code/Working/Utility and Misc/guardImage.m
1
function [ pixelVector ] = guardImage( image, mask, maskNumber)
2
%GUARDIMAGE applies a logical mask to an image and returns a
3
%one-dimensional array of the valid pixels
4
%   param maskNumber
5
%       maskNumber indicates what value in the image you are looking to
6
%       guard on. For example, if you want to guard on the foreground you
7
%       can provide a 1. If you want to get the background, then provide a
8
%       0. The default value is for the foreground, or a 1.
9
10
11
    %%Pre-process
12
    %check if a maskNumber is provided
13
    if ~exist('maskNumber','var')
14
        maskNumber=1;
15
    end
16
    
17
    %make an array of zeros
18
    pixelVector = zeros;
19
    
20
    %get size of image
21
    sizeImage = size(image);
22
    
23
    %array pos
24
    x = 1;
25
    
26
    %% create pixel vector from the mask
27
    for i=1:sizeImage(1)
28
       for j=1:sizeImage(2)
29
           if(mask(i,j) == maskNumber)
30
               %if part of the mask, then add to pixel vector
31
               pixelVector(x) = image(i,j);
32
               %increment
33
               x = x + 1;
34
           end
35
       end
36
    end
37