Step 1 - We read the image
image=imread("E:\sem 7\image vvideo coding\project\Pattern.jpg");
Step 1 - We read the image
image=imread("E:\sem 7\image vvideo coding\project\Pattern.jpg");
Step 2 - Then we gray the image
img=rgb2gray(image);
imshow(img)
Step 3 - Divide image into macroblocks.
Images are made out of pixels. But there are many pixels to process and if we apply transforms generally to the whole image the quality of the image will be destroyed. And also when there's a video to be compressed we have to check temporal correlations between adjacent frames. Analyzing them pixel by pixel takes a lot of computational power. Because of that to analyze the image we separate it to smaller blocks known as macroblocks.
function [C,img_y,img_x] = macroblocks(img,macroblock_size)
number_of_macroblocks = size(img,1)*size(img,2)/(macroblock_size^2);
img_y = size(img,1)/macroblock_size ;
img_x = size(img,2)/macroblock_size ;
row_ratio_array = 8*ones(1,floor(img_y)); %refer mat2cell.how matrixx is divided in y direction
column_ratio_array = 8*ones(1,floor(img_x));
C = mat2cell(img,row_ratio_array ,column_ratio_array);
end
Here the
img is the actual image we feed in the function
macroblock size is the number of pixels per macroblock.
img_y = number_of_macroblocks_per_height_of_the_image (rows)
img_x = number_of_macroblocks_per_length_of_the_image (columns)
By using cell arrays we can put 8x8 macroblocks in cells. Refer figure below
It's important to know how mat2cell works in matlab to understand this section of code.
Hence we create [8 8 8 8 .... ...8 ] vectors for the images x and y directions. BTW y is the height direction X is the length direction.