2016年2月21日星期日

Week 3 Reconstruction of Real Image

This week we tried to reconstruct a real image with different colors. The function imread() was used. The process was to reconstruct the image directly.

1.Read the image and store the data of each point in a matrix.
2.Set the numbers of the mask pattern using the numbers of pixels, this has been proved that the quality of reconstruction is the best.
3.Obtain the THz data and combine them to do the linear reconstruction. 
4.Use a simple function to compare the reconstructed image with the original image. The principle of this function is to compare the pixels of 2 different images.

We meet some problem in reconstructing the image. They are listed on the following:

1.The image should have equal length and width, the original image should be "square", the number of the pixels should be n × n.
2.MATLAB has its own limit on the size of the matrix. If the image is too large, the work can not be done. 

The flowchart is on the following: 



The matlab code of this part is on the following:

% test linear_rec(THzData, MaskData)
clear all;

o_ima=imread('5.jpg');

figure(1),subplot(2,3,1),imagesc(o_ima), title('original image')
% simulate mask set data

[a,b] = size(o_ima);
if a>b
   c=b;
else c=a;
end


H=im2double(o_ima);
ima=imresize(H,[c c]);
[m,n,l]=size(ima);



NP=c;
figure(1),subplot(2,4,1),imagesc(ima), title('original image')
% simulate mask set data
NM=200; % nunmber of masks
MaskData=zeros(NM,c*c);
subplot(2,4,2),im1=imagesc(ima);title('mask pattern')
subplot(2,4,3),im2=imagesc(ima);title('R combined')
subplot(2,4,4),im3=imagesc(ima);title('G combined')
subplot(2,4,5),im4=imagesc(ima);title('B combined')

for i=1:NM                                               
    temp=rand(c); temp=temp>0.5;
    MaskData(i,:)= temp(:);
    temp1=reshape(temp,c,c);%mask pattern
    set(im1,'CData',temp1);
    temp2=temp.*double(ima(:,:,1));%combined patten
    set(im2,'CData',temp2);
    temp3=temp.*double(ima(:,:,2));
    set(im3,'CData',temp3);
    temp4=temp.*double(ima(:,:,3));
    set(im4,'CData',temp4);


end
    temp5(:,:,1)=temp2;
    temp5(:,:,2)=temp3;
    temp5(:,:,3)=temp4;
    temp6=double(temp5);
    subplot(2,4,6),imagesc(temp6),title('combined');
   
    temp7=ima(:,:,1);
    THzData=double(MaskData)*double(temp7(:));
    newimg(:,:,1)=linear_rec(THzData, MaskData);
    temp7=ima(:,:,2);
    THzData=double(MaskData)*double(temp7(:));
    newimg(:,:,2)=linear_rec(THzData, MaskData);
    temp7=ima(:,:,3);
    THzData=double(MaskData)*double(temp7(:));
    newimg(:,:,3)=linear_rec(THzData, MaskData);
  
  
figure(1);subplot(2,4,7),imshow(newimg,[]);simliarity( ima, newimg );% display the reconstructed image
title('Reconstruction');
similarity(ima,newimg);

The code of the compare function is on the following:
function simliarity( ima, newimg )
%UNTITLED4 Summary of this function goes here
%   Detailed explanation goes here
I1=ima;
I2=newimg;
ssimval = ssim(I1,I2);

  
    fprintf('The ssim value is %0.4f.\n',ssimval);
  
    title(sprintf('Reconstruction - simliarity is %0.4f',ssimval));

end

And the result is on the following:

It was obviously this 2 pictures was different. The direct reconstruction illustrates failure. 

From the blog of last year, we learnt that there is one way, which was to decoration the axises with different value of the image, then combine them. Which is that we take the Red color, Green color and blue color out and to obtain the THz data, combing them separately. The flowchart is on the following:


And the matlab code:

% test linear_rec(THzData, MaskData)
clear all;

o_ima=imread('5.jpg');

figure(1),subplot(2,3,1),imagesc(o_ima), title('original image')
% simulate mask set data

[a,b] = size(o_ima);
if a>b
   c=b;
else c=a;
end


H=im2double(o_ima);
ima=imresize(H,[c c]);
[m,n,l]=size(ima);



NP=c;
figure(1),subplot(2,4,1),imagesc(ima), title('original image')
% simulate mask set data
NM=200; % nunmber of masks
MaskData=zeros(NM,c*c);
subplot(2,4,2),im1=imagesc(ima);title('mask pattern')
subplot(2,4,3),im2=imagesc(ima);title('R combined')
subplot(2,4,4),im3=imagesc(ima);title('G combined')
subplot(2,4,5),im4=imagesc(ima);title('B combined')

for i=1:NM                                               
    temp=rand(c); temp=temp>0.5;
    MaskData(i,:)= temp(:);
    temp1=reshape(temp,c,c);%mask pattern
    set(im1,'CData',temp1);
    temp2=temp.*double(ima(:,:,1));%combined patten
    set(im2,'CData',temp2);
    temp3=temp.*double(ima(:,:,2));
    set(im3,'CData',temp3);
    temp4=temp.*double(ima(:,:,3));
    set(im4,'CData',temp4);


end
    temp5(:,:,1)=temp2;
    temp5(:,:,2)=temp3;
    temp5(:,:,3)=temp4;
    temp6=double(temp5);
    subplot(2,4,6),imagesc(temp6),title('combined');
   
    temp7=ima(:,:,1);
    THzData=double(MaskData)*double(temp7(:));
    newimg(:,:,1)=linear_rec(THzData, MaskData);
    temp7=ima(:,:,2);
    THzData=double(MaskData)*double(temp7(:));
    newimg(:,:,2)=linear_rec(THzData, MaskData);
    temp7=ima(:,:,3);
    THzData=double(MaskData)*double(temp7(:));
    newimg(:,:,3)=linear_rec(THzData, MaskData);
  
  
figure(1);subplot(2,4,7),imshow(newimg,[]);simliarity( ima, newimg );% display the reconstructed image
title('Reconstruction');
similarity(ima,newimg);



In next week, we will try some other solutions to deal with large images. This week we meet the dilemma here.








没有评论:

发表评论