【图像修复】损坏图像修复【含Matlab源码 731期】

在这里插入图片描述

⛄一、获取代码方式

获取代码方式1:
完整代码已上传我的资源:【图像修复】基于matlab损坏图像修复【含Matlab源码 731期】
点击上面蓝色字体,直接付费下载,即可。

获取代码方式2:
付费专栏Matlab图像处理(初级版)

备注:
点击上面蓝色字体付费专栏Matlab图像处理(初级版),扫描上面二维码,付费29.9元订阅海神之光博客付费专栏Matlab图像处理(初级版),凭支付凭证,私信博主,可免费获得1份本博客上传CSDN资源代码(有效期为订阅日起,三天内有效);
点击CSDN资源下载链接:1份本博客上传CSDN资源代码

⛄二、部分源代码

clc; clear all;
%First part
%reading img1, saving as im1 variable
im1 = imread(‘img1.jpg’);
%for boundary it’s a must to convert to gray
im1 = rgb2gray(im1);
subplot(331), imshow(im1), title(‘Img1 convert to gray’);
% as a mask all colors will be white or black
mask = im1 < 255;
subplot(332), imshow(mask), title(‘Apply a mask’);
%invert colors, otherwise the boundary sees nearly
%the whole image, need to swap colors
mask = imcomplement(mask);
subplot(333), imshow(mask), title(‘Invert colors’);
%gives location x y coordinates where is the first area,
%it starts there too
%if don’t have ; at the end, it shows the dimensions of
%the image
dim = size(mask)
col = round(dim(2)/2)-90;
row = min(find(mask(:,col)))

%an interesting drawback, if I would fill the “holes”
%with erode function which is better then imfill, the
%program can’t see any of the boundaries, hence in the
%for loop I had to use 180 rounds, otherwise can’t see
%the big parts.
%erode image
% se = strel(‘line’,10, 90);
% boundaries = imerode(mask,se);
% imshow(boundaries);

%use bwtraceboundary function to find the boundary from
%the above declared point.
%it needs a binary image, row and col coordinates for start
%and direction, W for west so left.
boundary = bwtraceboundary(mask,[row, col],‘W’);
subplot(334), imshow(im1), title(‘Boundaries’);
hold on;
plot(boundary(:,2),boundary(:,2),‘g’,‘LineWidth’,4);
%the imfill fills the smaller objects. However, as I
%mentioned above the erode function does better job.
%Unfortunately, with that result the for loop cannot
%find any boundaries, despite the imshow(mask)black&white
%image looks better.
BW_filled = imfill(mask,‘holes’);
boundaries = bwboundaries(BW_filled);
%shows the border of all white part, with the imfill
%function the for loop must iterate 180 times, hilarious.
%Under 180 it doesn’t find the last top right big white
%object.
for k=1:180
b = boundaries{k};
plot(b(:,2),b(:,1),‘g’,‘LineWidth’,4);
end

%Second part
%denoise test; averaging or median filter
im2 = imread(‘Penguins.jpg’);
im2 = imresize(im2, [768, 1024]);
rgbImage = im2;
subplot(335), imshow(rgbImage), title(‘Resized but noisy Img2’);
%averaging filter
mat = ones(5,5)/25;
averagingFilter_im2 = imfilter(rgbImage, mat);
subplot(336), imshow(averagingFilter_im2), title(‘Img2 averaging filter’);

%median filter
for k=1:3
medianFilter_im2(:,:,k)=medfilt2(rgbImage(:,:,k),[3,3]);
end
subplot(337), imshow(medianFilter_im2), title(‘Img2 median filter’);

%Third part
im1 = imread(‘img1.jpg’);
recoveredImage = im1;
recoveredImageMedianFilter = im1;

zero = recoveredImage == 255;
recoveredImage(zero) = averagingFilter_im2(zero);

zero1 = recoveredImageMedianFilter == 255;
recoveredImage(zero1) = averagingFilter_im2(zero1);
recoveredImageMedianFilter(zero1) = medianFilter_im2(zero);

subplot(338), imshow(recoveredImage), title(‘Recovered image with averaging filter’);
subplot(339), imshow(recoveredImageMedianFilter), title(‘Recovered image with median filter’);
%Compare recoveredImage and originalImage

meanRecoveredIm = mean(recoveredImage(😃)
meanOriginalIm = mean(originalImage(😃)
%It coutns the Structural Similarity Index (SSIM) value
%for original and recovered image.
ssimValue = ssim(originalImage, recoveredImage)
%It counts the Peak Signal to Noise Ratio value
%for original and recovered image. They must be the same
%class and size as well.
peaks2NoiseRatio = psnr(originalImage, recoveredImage)
%It counts the Mean Squared Error (MSE) between arrays
%of the 2 declared variable, currently the original and the recovered image.
meanSquaredErr = immse(originalImage, recoveredImage)

⛄三、运行结果

在这里插入图片描述

⛄四、matlab版本及参考文献

1 matlab版本
2014a

2 参考文献
[1] 陈少锋.数字图像修复技术及其在图像压缩中的应用[J].电脑知识与技术. 2018,14(24)

3 备注
简介此部分摘自互联网,仅供参考,若侵权,联系删除

  • 11
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Matlab领域

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值