Code covered by the BSD License  

Highlights from
Get subwindow of image

image thumbnail
from Get subwindow of image by Lukas Tencer
Function for sampling of small images from big images. At x,y gets an image of sizex,sizey.

get_subwindow( inputImage, y, x, sizey, sizex , borderPolicy)
function [ result ] = get_subwindow( inputImage, y, x, sizey, sizex , borderPolicy)
%GET_SCRIPT Get subminge of image with a given border policy
%   Get subimage at x,y center coordinates, witht a given border replication
%   policy and size of window

	%input_image = [inputmage]
    
    shiftx=sizex/2;
    shifty=sizey/2;
    
    minCondition=(x-shiftx<1)&&(y-shifty<1);
    maxCondition=(x+shiftx>size(inputImage,2))&&(y+shifty>size(inputImage,1));
    padded=0;
    
    if(minCondition || maxCondition)
        sampleImage=padarray(inputImage, [shiftx+1,shifty+1], borderPolicy);
        padded=1;
    end
        
    if(padded==0)
        result=inputImage(y-shifty:y+(shifty)-1,x-shiftx:x+(shiftx)-1,:);
    else
        result=sampleImage(y+sizey:y+(sizey*2)-1,x-sizex:x+(sizex*2)-1,:);
    end
    
end

Contact us