classdef janis_patternMat < janis_pattern

   properties (SetAccess = public)
       ImgType = 'image simple';
   end

  properties (SetAccess = protected)
      imgFiles;             % list of image files (mat-files!)
  end

  methods

       function obj = janis_patternMat(listOfImages)
            for imgCount =1:numel(listOfImages)
                try
                    obj = obj.addImage(listOfImages{imgCount});
                catch excep
                % exception handlig if no image found
                    error('Unable to find image: %s',listOfImages{imgCount});
                    rethrow(excep);
                end
            end
       end

           % adds a new image
        function obj = addImage(obj,image)
            obj.imgFiles{size(obj.imgFiles,2)+1} = image;
        end

        function jp = generatePattern(jp)
            for imgCount=1:numel(jp.imgFiles)
                if ~isempty(jp.imgFiles{imgCount})
                    try
                        tmp = load(jp.imgFiles{imgCount},'Y');
                        images{imgCount} = tmp.Y;
                    catch excep
                        error('Loading image failed: %s', jp.imgFiles{imgCount});
                        rethrow(excep);
                    end
                end
            end
            fs = getFeatureSelection(jp);
            images = fs.reduce(images{:});
            if ~isempty(images)
                jp.VoxelValues = images;
                jp.isLoaded = true;
            else
                warning('janis:emptyImg','Image was empty, something went wrong');
                jp.isLoaded = false;
            end
        end

  end


end