From: arvind on 2 Apr 2010 23:30 how do i do this from the codes i have? Write a function to handle 3 parameters: a. [infile] used to point to the input file name containing your image to be compressed. b. [outfile] used to define the output file name of the compressed image. c. [Coeff] used to allow specification of the total number of coefficients with the most energy. 1. Convert the input RGB components to double precision and Perform 2D DCT for the respective RGB components to achieve 3 separate variables of the same dimension 2. Double dct values above original values 3. Create new variables of similar dimension to the dct values. 4. Sort elements in ascending order 5. Flip ascending order about the horizontal axis to reposition higher value components at the top left hand corner. 6. Create an exact 2dimentional matrix containing all zeros, with dimension similar to the original R,G,B components. 7. Map the DCT results based on the new dimension created above and taking reference to the indexed matrix that contains the higher values starting from the top left hand corner. 8. Perform 2D Inverse DCT with IDCT2 to convert your compressed image back for display. 9. Create an empty canvas with dimension similar to the IDCT2 results to containing all zeros and map it with the IDCT2 values for all R,G,B components. 10. Convert the above canvas containing the IDCT2 values to uint8 format. 11. Write the processed image to output file. 12. Show image on display, and conclude on your observation. my codes: function [im]=Compr(infile,coeff,outfile) %input [a,map1]=imread(infile); subplot(2,1,1), imshow(a,map1) % red = double(a(:,:,1)); green = double(a(:,:,2)); blue = double(a(:,:,3)); red_dct=dct2(red); green_dct=dct2(green); blue_dct=dct2(blue); red_pow = red_dct.^2; green_pow = green_dct.^2; blue_pow = blue_dct.^2; red_pow=red_pow(:); green_pow=green_pow(:); blue_pow=blue_pow(:); [B_r,index_r]=sort(red_pow); [B_g,index_g]=sort(green_pow); [B_b,index_b]=sort(blue_pow); index_r=flipud(index_r); index_g=flipud(index_g); index_b=flipud(index_b); im_dct_r=zeros(size(red)); im_dct_g=zeros(size(green)); im_dct_b=zeros(size(blue)); for ii=1:coeff im_dct_r(index_r(ii))=red_dct(index_r(ii)); im_dct_g(index_g(ii))=green_dct(index_g(ii)); im_dct_b(index_b(ii))=blue_dct(index_b(ii)); end im_r=idct2(im_dct_r); im_g=idct2(im_dct_g); im_b=idct2(im_dct_b); im=zeros(size(red,1),size(red,2),3); im(:,:,1)=im_r; im(:,:,2)=im_g; im(:,:,3)=im_b; im=uint8(im); imwrite(im, outfile); subplot(2,1,2), imshow(im,map1) return;
|
Pages: 1 Prev: noise and gamma correction Next: Difference between Search and Poll method in Pattern Search |