The following Matlab project contains the source code and Matlab examples used for dft & dct. Code provided here works for 1-D signal. If you want to process it for 2-D signal (ex. GrayScale Image) first process the signal row wise and after that column wise.
The source code and files included in this project are listed in the project files section, please make sure whether the listed source code meet your needs there.