This is the assignment of Digital Image Processing in the last semester. The teacher asked us to compare the effects of DFT, WHT, and DCT transformations after compression. I spent two nights doing some things, in order to facilitate future generations to do better and minimize the cost, the special upload program is so far, the program quality is very low, and you are welcome to give your valuable comments.
The first is the image segmentation program. Some people use mat2cell or the like. Because the cell concept is not very clear, I used a very stupid method to do the loop, after processing a large image, it is converted into a 4-dimensional array. In the 4-dimensional array, the first two dimensions are the horizontal and vertical left of the image, and the last two dimensions are the position of the sub-image in the big image, thus, image segmentation is achieved. Is it stupid.
Function sub_image = div_image (scr_image, subsize) % function: Split scr_image by subsize * subsize % input: scr_image: image to be processed, subsize sub-image size % output: sub_image: sub-image set, p, q is the serial number % Note: Only two-dimensional images can be processed, that is, grayscale images % edit by lineter % QQ: 542375845% Ningxia DAXUE % example: % a=imread('jinbo.bmp '); % A = rgb2gray (a); % B = div_image (A, 16); % size (B) % ans = % 16 32 32% if (ndims (scr_image) = 3) scr_image = rgb2gray (scr_image); end [x, y] = size (scr_image ); for p = 1: Round (x/subsize) for q = 1: round (y/subsize) sub_image (:,:, p, q) =... scr_image (subsize * (p-1) + 1: subsize * P, subsize * (q-1) + 1: subsize * q); endendif (mod (x, subsize )~ = 0 | Mod (Y, subsize )~ = 0) disp ('warning, the image edge may be lost! '); End
This is a very stupid method. If you use built-in functions to implement segmentation, please let me know. Thank you very much.
The corresponding image merging method is as follows:
Function image = sum_image (div_image) % function: Merge scr_image into an image % input: scr_image: image set to be processed % output: sub_image: Generate image % note: only two-dimensional images can be processed, that is, grayscale images % edit by lineter % QQ: 542375845% Ningxia DAXUE % example: % a1_imread('jinbo.bmp '); % A = rgb2gray (); % B = div_image (A, 16); % size (B) % ans = % 16 32 32% if (ndims (div_image )~ = 4) disp ('image format error, not image set'); end [x, y, m, n] = size (div_image); If (x ~ = Y | M ~ = N) disp ('incorrect image size'); endimage = []; for p = 1: m for q = 1: m image (X. * (p-1) + 1) :( X. * P), (X. * (q-1) + 1) :( X. * q) = uint8 (div_image (:,:, p, q); endendimage = uint8 (image );
After this processing, the image will be merged. In between the two functions, you can perform some transformation, compression, and so on. After restoration, you can know the compression effect after comparing it with the source image.