Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

how to recombine 8x8 block to form original image

Status
Not open for further replies.

gaurav007

Newbie level 4
Joined
Mar 10, 2013
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,319
sir I am a research scholar, and currently working on lossy image compression using FFT.
The proposed FFT/IFFT algorithm is also folIows:
  1. Read the input file from the host system.
  2. Evaluate the (8x8) Cosine and Sine matrix using Equations.

    C(u+l, x+l) = cos(pi / 4)*(u* x))

    S(u + 1, x + 1) = sin(pi / 4) * (u * x))


  3. The image is accessed as (8x8) block successively, and the Cosine and Sine transforms are obtained.
  4. Compute the FFT of the image using basic equation.
  5. Verify the obtained FFT values with buiIt in FFT functional values of MATLAB.
  6. Compute the IFFT of the processed image in step 4 using the Eq.
  7. Verify visually the reconstructed image with the original image.
  8. Calculate the Power Signal to Noise Ratio (PSNR) of the processed signals for validation.
Note: A PSNR value of 35 dB and above implies the reconstructed image is indistinguishable from the original image.

So far i have done this

clc;
clear all;
close all;
I_color=imread('lena.jpg');
I=rgb2gray(I_color);
[r,c,p]= size(I);
subplot(2,2,1);
imshow(I_color);
title('Original Image');
subplot(2,2,2);
imshow(I);
title('Grayscaled');
bs=8;
nob=r/bs;
xx=0;
% creating cos and sine matrix
for u=0:7
for x=0:7
C(u+1,x+1)= cos((pi/4)*(u*x)); %cos matrix
S(u+1,x+1)= sin((pi/4)*(u*x)); %sine matrix
C= im2uint8(C);
S= im2uint8(S);
end
end
%Ctransform = zeros(8,8,64);
for k=1:r/bs
for j=1:c/bs
block:),:,xx+j)= I(bs*(k-1)+1:bs*(k-1)+bs,bs*(j-1)+1:bs*(j-1)+bs);
Ctransform:),:,xx+j)= immultiply(C,block:),:,xx+j));
Stransform:),:,xx+j)= immultiply(S,block:),:,xx+j));
end
xx=xx+(r/bs);
end
yy=0;
%F=im2uint8(zeros(512,512));
Fblock=im2uint8(zeros(8,8,64));
for M=1:64
for N=1:64
Fblock:),:,yy+N)=Ctransform:),:,yy+N) +imag((Stransform:),:,yy+N)));
% F(bs*(M-1)+1:bs*(M-1)+bs,bs*(N-1)+1:bs*(N-1)+bs) = Fblock;
end
yy=yy+64;
end

now i want to recombine Fblock (fft of each block) after taking inverse fft plz help me out i am confused a lot
 

if your using image processing toolbox there is something called blockproc where you can divide an image into a 8x8 blocks provided the image resolution is divisible by 8. For example a 512x512 image can be divided into 64 rows and 64 columns of 8x8 image blocks. You can also get the image back after performing your FFT/DFT. You need an image processing toolbox to use this function.

However I had created my own blockproc function code and customised it for images of different sizes. Its much easier to have your code if you do not have image toolbox. I used it for performing DFT and IDFT of image for digital wartermarking.

You can save each block FFT data in a matrix array, do the IFFT and then copy into an output image. But first you need to create an output image with 0 pixel values by defining output_image = zeros[r,c] in the beginning and then transferring IFFT block data into the output image. You need to again use two for loops like how you did it for the FFT part.
 
Last edited:

thanks for reply
i have tried using blockproc but in my algorithm i have to perform various operation one after another
thus i am unable to build 'fun' for blockproc.
kindly help me out to complete the code
 

like I said in a previous comment you need to pass the IFFT data block into a vector matrix and save it into an empty defined image matrix variable where you save this IFFT data. Check the comment below

You can save each block FFT data in a matrix array, do the IFFT and then copy into an output image. But first you need to create an output image with 0 pixel values by defining output_image = zeros[r,c] in the beginning and then transferring IFFT block data into the output image. You need to again use two for loops like how you did it for the FFT part.
 
till now i have done this
i am getting a black image after performing IFFT
Code:
clc;
clear all;
close all;  
I_color=imread('lena.jpg');
I=double(rgb2gray(I_color));
[r,c,p]= size(I);
subplot(2,2,1);
imshow(I_color);
title('Original Image');
bs=8;
nob=r/bs;
xx=0;
% creating cos and sine matrix
C=zeros(8,8);
S=zeros(8,8);
for u=0:7
    for x=0:7
        C(u+1,x+1)= cos((pi/4)*(u*x)); %cos matrix
        S(u+1,x+1)= sin((pi/4)*(u*x)); %sine matrix
        
    end
end

block = zeros(8,8,4096);
Ctransform = zeros(8,8,4096);
Stransform = zeros(8,8,4096);
    for k=1:r/bs
        for j=1:c/bs
          block(:,:,xx+j)=  I(bs*(k-1)+1:bs*(k-1)+bs,bs*(j-1)+1:bs*(j-1)+bs);
          Ctransform(:,:,xx+j)= immultiply(C,block(:,:,xx+j));
          Stransform(:,:,xx+j)= immultiply(S,block(:,:,xx+j));
        end
        xx=xx+(r/bs);
     end
 
yy=0;

Fblock=zeros(8,8,4096);
F=zeros(512,512);
%calculation for FFT
for M=1:r/bs
    for N=1:c/bs
             Fblock(:,:,yy+N)=Ctransform(:,:,yy+N) + (imag((Stransform(:,:,yy+N))));
             F(bs*(M-1)+1:bs*(M-1)+bs,bs*(N-1)+1:bs*(N-1)+bs)= Fblock(:,:,yy+N);
         
    end
        yy=yy+(r/bs);
          
end
zz=0;
%calculation of IFFT
for K=1:r/bs
    for L=1:c/bs
         IFblock(:,:,zz+N)= (1/4096)*((Fblock(:,:,zz+N))*C) - (Fblock(:,:,zz+N))*(imag(S) );
           original(bs*(M-1)+1:bs*(M-1)+bs,bs*(N-1)+1:bs*(N-1)+bs)= IFblock(:,:,zz+N);
    end
    zz=zz+(r/bs);
end

subplot(2,2,2);
imshow(uint8(F));
title('FFT Of Image');
subplot(2,2,3);
imshow((original));
title('IFFT of Image');

plz help me out
 

Did you perform IFFT and put the pixels back into the right position in the output image??. Remember your doing IFFT of just a block of pixels, you need to perform the same for all the pixel blocks and then put in back into the empty output image defined in the correct order so that your image pixels are right.
 

Did you perform IFFT and put the pixels back into the right position in the output image??. Remember your doing IFFT of just a block of pixels, you need to perform the same for all the pixel blocks and then put in back into the empty output image defined in the correct order so that your image pixels are right.

yes i have perform IFFT and put the pixels back into the right position in the output image in last part, i have calculate the IFFT of the block and allocate its position and running the loop for 4096 times i can get the original image
Code:
%calculation of IFFT
for K=1:r/bs
    for L=1:c/bs
         IFblock(:,:,zz+L)= (1/4096)*((Fblock(:,:,zz+L))*C) - (Fblock(:,:,zz+L))*(imag(S) );
           original(bs*(K-1)+1:bs*(K-1)+bs,bs*(L-1)+1:bs*(L-1)+bs)= IFblock(:,:,zz+L);
    end
    zz=zz+(r/bs);
end
 
Last edited:

When you are able to get the image back then your problem is solved right??
 

When you are able to get the image back then your problem is solved right??

problem is that i am not getting the original image, the image after performing ifft is black with white dot on it.
my input image is Leena
and the output is attached here original.jpg
 

can u do IFFT for one block part of the image. Do it for the first block of the image and then do IFFT and see if the output your getting is correct. You are doing FFt for a gray image right??
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top