【图像还原】基于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