【圖像還原】基於matlab圖像數據還原【含Matlab源碼 1175期】

1、簡介

基於matlab圖像數據還原markdown

2、源代碼

%% 對所截圖P0('QQ截圖20190825233353.jpg')進行處理  獲得P1 '2017.0221-1.png'
clear;clc;
I=imread ('QQ截圖20190825233353.jpg');
bw=rgb2gray(I);  %轉換成灰度
bw1=bw>20;  %灰度值越大,顏色越淺.  bw1的值非0即1.
imwrite(bw1,'2017.0221-1.png','png')  %保存爲png灰度文件。
%% 對P1手動擦除不須要的部分獲得P2 2017.0221-1-1.png
%% 對P2 關於X軸對稱 在MAT上獲得與P0的相同的P3 
 clc;
clear;
I=imread ('2017.0221-1-1.png');
bw=rgb2gray(I);
bw1=bw>1;  %灰度值越大,顏色越淺.  bw1的值非0即1.
[tempy,tempx] = find(bw1==0);

figure
% plot(tempx,tempy,'.','MarkerSize',4) 
% hold on
%plot(tempx,tempy)
% grid on; 
tempy = 0 - tempy + 321;  %作X軸對稱,image is 574*321px
plot(tempx,tempy,'.','MarkerSize',4)
% hold on
% grid on; 
%% %----平移座標軸---圖片總大小:574*321px--------------------P0中的原點的像素位置(156,191)用畫板找
tempx = tempx -156;
tempy = tempy -(321-191);  %這個地方本身慢慢想一想- (419-258)
% plot(tempx,tempy,'.','MarkerSize',4);
% % hold on
% grid on;
%% 縮放
%在原圖中(0,0)的像素點爲(156,191);(100, 100)的像素點爲(260, 79)
%則X軸縮放比例爲100/(260-156),y軸縮放比例爲100/(191-79)

tempx=tempx*(100/(260-156));
tempy=tempy*(100/(191-79));
plot(tempx,tempy,'.','MarkerSize',4)
axis([-150 400 -150 250]); % 設置座標軸在指定的區間 xmin xmax ymin ymax
grid on;
%此時已經恢復爲原圖P0了
%% 去重:刪除同一個x對應的多個y
toDel = [];

for i=1:( length(tempx) - 1)

    if( tempx(i)==tempx(i+1) )

        toDel = [toDel i];
    end
end

3、運行結果

在這裏插入圖片描述

4、備註

版本:2014aide

相關文章
相關標籤/搜索