function [ G ] = D35WQ8_DCT( g )
    
    
    %% Kernel base definition
    
    
    % batch can hold G channels or channels*G_batch
    % for improved process time
    
    % Supposing it is still matlab in NHWC
    % Using N*C WH where N*C -> batch, since they have to be processed
    % separately
    
    [N, H, W, C] = size(g);
    batch = N * C;
    
    % NHWC -> NCHW
    g = permute(g, [1, 4, 2, 3]);
    % NCHW -> N*C H*W
    g_flat = reshape(g, batch, H*W);
   
    [X, Y] = meshgrid(1:H, 1:W);
    
    % alpha norm function
    n = @(u)(((u~=1)*1)+((u==1)*1/sqrt(2)));
    c = @(u,v) (sqrt(4/H/W)*n(u)*n(v));
    % f(u,v) returns a kernel with index (u,v) on a fixed N1, N2 basis
    f = @(u,v) c(u,v)*cos((2*X-1)*(u-1)*pi./2./H).*cos((2*Y-1)*(v-1)*pi/2/W);
    
    % K will hold all the kernels flattened
    K = zeros(H*W, H*W);
    for u=1:H
        for v=1:W
            % row major order into columns
            K(:, u+(v-1)*H) = reshape(f(u, v), 1, []);
        end
    end
    
    
    
    
    %% Computing the output in batches
    
    % [N*C, H*W] x [H*W, H*W] -> [N*C, H*W]
    G_flat = g_flat*K;
    
    
    % N*C H*W -> NCHW
    G = reshape(G_flat, N, C, H, W);
    
    % NCHW -> NHWC
    G = permute(G, [1,3,4,2]);
end

