Home > data-import > supporting_functions > seperate_seg.m

seperate_seg

PURPOSE ^

Seperate the image from into four segmentions

SYNOPSIS ^

function segs = seperate_seg(inputIm, scale)

DESCRIPTION ^

 Seperate the image from into four segmentions
 
 segs = seperate_seg(inputIm);
   Input:
     inputIm: binary image read from img_?_seg.tif
   Output:
     segs: 4 cell arrays *ymid*xmid matrix (where [ymid xmid] = round(size(inputIm)) )
           segs(1,:,:) is the segmentation for hands and faces
           segs(2,:,:) is the segmentation for object 1
           segs(3,:,:) is the segmentation for object 2
           segs(4,:,:) is the segmentation for object 3

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function segs = seperate_seg(inputIm, scale)
0002 % Seperate the image from into four segmentions
0003 %
0004 % segs = seperate_seg(inputIm);
0005 %   Input:
0006 %     inputIm: binary image read from img_?_seg.tif
0007 %   Output:
0008 %     segs: 4 cell arrays *ymid*xmid matrix (where [ymid xmid] = round(size(inputIm)) )
0009 %           segs(1,:,:) is the segmentation for hands and faces
0010 %           segs(2,:,:) is the segmentation for object 1
0011 %           segs(3,:,:) is the segmentation for object 2
0012 %           segs(4,:,:) is the segmentation for object 3
0013 
0014 %
0015 if isempty(inputIm)
0016     segs = [];
0017     return;
0018 end
0019 if ~exist('scale','var') || isempty(scale)
0020     scale = 2;
0021 end
0022 
0023 %check to make sure image is binary
0024 if numel(unique(inputIm)) ~= 2
0025     error('input image not binary');
0026 end
0027 
0028 %clear cross
0029 columns = sum(inputIm,1) == size(inputIm,1); %finds columns filled with 1s
0030 rows = sum(inputIm,2) == size(inputIm, 2); %finds rows filled with 1s
0031 newIm = inputIm;
0032 newIm(:,columns) = 0; %sets these columns to 0
0033 newIm(rows,:) = 0; %sets these rows to 0
0034 
0035 % clear cross
0036 [ymax, xmax] = size(inputIm);
0037 % newIm = inputIm;
0038 ymid = round(ymax/2);
0039 % newIm(ymid,1:xmax) =  zeros(xmax,1);
0040 xmid = round(xmax/2);
0041 % newIm(1:ymax,xmid) =  zeros(ymax,1);
0042 
0043 %segs = zeros(4, ymax, xmax);
0044 %segs = segs>1;
0045 
0046 % For logical data, using 'nearest' in imresize can be faster and get same result
0047 segs{1} = imresize(newIm(1:ymid, 1:xmid), scale, 'nearest');
0048 segs{2} = imresize(newIm(1:ymid, xmid+1:xmax), scale, 'nearest');
0049 segs{3} = imresize(newIm(ymid+1:ymax, 1:xmid), scale, 'nearest');
0050 segs{4} = imresize(newIm(ymid+1:ymax, xmid+1:xmax), scale, 'nearest');

Generated on Tue 23-May-2017 03:00:58 by m2html © 2005