重新安装补丁在Matlab中制作图像

时间:2018-01-10 21:46:52

标签: matlab image-processing pca sar

我正在尝试在MATLAB中实现一个算法,该算法涉及将SARBM3D应用于PCA。现在我几乎已经实现了所需的步骤。在将图像分割成子图像后,我坚持将图像重新分配到一个图像。你能指导我吗?

代码如下:

RGB = imread('sar1.jpg');

%% Resize image 
rgbImage = imresize(RGB, [128 128]);
[rows, columns, numberOfColorBands] = size(rgbImage);
% Display the original color image.
%subplot(2, 2, 1);
%imshow(rgbImage, []);

%%Split image into 2 sub images
col1 = 1;
col2 = floor(columns/2);
col3 = col2 + 1;
row1 = 1;
row2 = floor(rows/2);
row3 = row2 + 1;
% Now crop
Left = imcrop(rgbImage, [col1 row1  col2 rows]);

Right = imcrop(rgbImage, [col2 row1  columns rows]);

%%Making n sub images
[m,n,o] = size(Left);
[m,n,o] = size(Right);
nblockcolumn = 3;
nblockrow = 4;
dcol = fix(n/nblockcolumn);
drow = fix(m/nblockrow);
indices = reshape(1:nblockrow* nblockcolumn,nblockcolumn,nblockrow);
for index = 1:nblockrow* nblockcolumn
    [r,c] = ind2sub([nblockrow,nblockcolumn],index );
    subimage = Left((r-1)*drow+1:r*drow, (c-1)*dcol+1:c*dcol,:); %Dividing left sub image to blocks 5*5
    subimage_right=Right((r-1)*drow+1:r*drow, (c-1)*dcol+1:c*dcol,:); %dividing right image to sub blocks 5*

    %%Applying meanshift clustering on all patches 
    rgbImage_ms=MeanShiftCluster_final(subimage,70,3,3);
    rgbImage_rs=MeanShiftCluster_final(subimage_right,70,3,3);

    %%storing image in array 
    imgs{index}=rgbImage_ms;
    img{index}=rgbImage_rs;

    %Find mean and variance to apply PCA & Apply PCA
    me_left= mean2(cell2mat(imgs));
    me_right=mean2(cell2mat(img));

    X1=rgb2gray(imgs{index});
    X2=rgb2gray(img{index});
    V1=var(double(X1));
    V2=var(double(X2));

    [LefCOEFF,scoresL]=pcacov(V1);
    [RigCOEFF,scoresR]=pcacov(V2);

    %%Apply LMMSE shrinkage on all patches 
    [LeftSigma]=LMMSE(LefCOEFF);
    [rightSigma]=LMMSE(RigCOEFF);

    %Transformation from PCA domain to pixel domain 
    Xl=[LeftSigma];
    Xr=[rightSigma];
    %For Left Side
    nComp = 128;
    XhatL = scoresL(:,1:nComp) * LefCOEFF(:,1:nComp)';
    XhatL = bsxfun(@plus, XhatL, me_left);
    fprintf('\n Left Side PCA Inverse');
    XhatL(1,:);

    %For Rigth Side
    XhatR = scoresR(:,1:nComp) * RigCOEFF(:,1:nComp)';
    XhatR = bsxfun(@plus, XhatR, me_right);
    fprintf('\n Right Side PCA Inverse');
    XhatR(1,:);

    LeftNewC{index} = {XhatL};
    RigthNewC{index} = (XhatR);
end

LeftNew=mat2cell(LeftNewC,[nblockcolumn,nblockrow]);
RightNew=mat2cell(RigthNewC,[nblockcolumn,nblockrow]);
LeftNew=uint8(LeftNew);
RightNew=uint8(RightNew);
NewImage = [LeftNew,RightNew];

%Recombine all patches 
%Recombine both 2 sub images 

现在我已经写了LMMSE和Meanshift的功能,我显然不需要在这里显示它们。到目前为止,我已经成功地获得了结果。我和alos一起反转了PCA。但我坚持重新组合图像。

任何帮助都会很棒。

0 个答案:

没有答案