function [x, x_pos, imagerows, imagecols] = cut_evzr(filename, w, h);

%clear all;
%close all;
%w=4;
%h=4;
%filename='E:\Temple\2004 Fall CIS 601\Code\PCA_new\small.jpg'

ws=w*2;
hs=h*2;

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*ws + 2*(hs-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 4x4 blocks
x_temp1 = im2col(image,[h w],'distinct');
x_temp1_rows = size(x_temp1,1);
x_temp1_cols = size(x_temp1,2);

%build 8x8 blocks
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);
       
        x_temp(:,k)=[LU(1:4);LD(1:4);LU(5:8);LD(5:8);...
                     LU(9:12);LD(9:12);LU(13:16);LD(13:16);...
                     RU(1:4);RD(1:4);RU(5:8);RD(5:8);...
                     RU(9:12);RD(9:12);RU(13:16);RD(13:16)];
    	
        x_pos(:,k)=[j;j+1;j+blockrows;j+blockrows+1];
        
        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));
