function [ coefficients, image_size ] = mDCT8x8( source_image ) M = 8; A = mDCT_A_Matrix( M ); [ row_max, col_max ] = size( source_image ); row_pad = rem( 8-rem( row_max, 8 ), 8 ); col_pad = rem( 8-rem( col_max, 8 ), 8 ); average = mean( mean( source_image ) ); source_image = [ source_image, ones( row_max, col_pad )*average; ones( row_pad, col_max + col_pad )*average ]; for col = 1:8:col_max for row = 1:8:row_max coefficients( row:row+7, col:col+7 ) = A*source_image( row:row+7, col:col+7 )*A'; end end image_size = [ row_max, col_max ];