function [x, x_pos, imagerows, imagecols] = cut_evzr5(image, w, h);



ws=w*2;%big block size
hs=h*2;%big block size

image = imread(filename);
figure; imshow(image)

YIQ = rgb2ntsc(image);
YIQ = double(image)./255; 
image = YIQ(:,:,1);
figure; imshow(image)



%define rows of the resulting x
newrows = 2*hs+2*(ws-2);

rows = size(image,1);
cols = size(image,2);

fprintf(1,'Size of the original image %d %d\n',rows, cols);

%modified code
marginh = mod(rows,hs);
marginw = mod(cols,ws);

image([rows-marginh+1:end],:) = [];
image(:,[cols-marginw+1:end]) = [];

imagerows = size(image,1);
imagecols = size(image,2);

blockrows=imagerows/h;
blockcols=imagecols/w;

%get hxw blocks
x_temp1 = im2col(image,[h w],'distinct');
x_temp1_rows = size(x_temp1,1);
x_temp1_cols = size(x_temp1,2);

%build hsxws blocks, i.e., big blocks from small blocks
%LU RU
%LD RD
k=1;
x_temp = zeros(hs*ws,(imagecols/ws*2-1)*(imagerows/hs*2-1));

for i=1:1:blockrows-1
    for j=i:blockrows:(x_temp1_cols-blockrows)        
        LU=x_temp1(:,j);
        LD=x_temp1(:,j+1);
        RU=x_temp1(:,j+blockrows);
        RD=x_temp1(:,j+blockrows+1);
       conctx=[];
        for ri=1:w
            conctx=[conctx; LU(1+(ri-1)*h:ri*h);LD(1+(ri-1)*h:ri*h)];
        end
        for ri=1:w
            conctx=[conctx; RU(1+(ri-1)*h:ri*h);RD(1+(ri-1)*h:ri*h)];
        end
    	x_temp(:,k)=conctx;
        x_pos(:,k)=[j;j+1;j+blockrows;j+blockrows+1];% indices of small blocks that compose a given big block
        
        k=k+1;                
    end
end    

x_temp_rows = size(x_temp,1);
x_temp_cols = size(x_temp,2);

y = zeros(newrows,x_temp_cols);

%copy 28 cells for each block
for m = 1:1:x_temp_cols
    k = 1;    
    %take the first row
    for n = 1:ws:x_temp_rows
        y(k,m) = x_temp(n,m);
        k = k + 1;
    end
    %take the last col
    for n = (n+1):1:x_temp_rows
        y(k,m) = x_temp(n,m);
        k = k + 1;
    end
    %take the last row
    for n = (x_temp_rows - hs):-ws:hs
        y(k,m) = x_temp(n,m);
        k = k + 1;
    end
    %take the first col    
    for n = (hs-1):-1:2
        y(k,m) = x_temp(n,m);
        k = k + 1;
    end
end

x = y;

fprintf(1,'Whole image cut and stripped, size %d %d\n', size(x));
