【图像修复】损坏图像修复【含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
    评论
### 回答1: 图像修复是指对受损或缺失的图像进行恢复和修补的过程。常见的图像修复算法有GUI FMM(图形用户界面的快速行进法)、Criminisi算法等。 GUI FMM(Graphical User Interface Fast Marching Method)是一种基于图形用户界面的快速行进法,可以用于彩色图像修复。该算法通过计算图像中每个像素点的梯度和局部特征,对损坏的像素进行修复。在修复的过程中,GUI FMM算法可以根据像素间的相似性进行补全,以获得更加真实和连续的修复结果。该算法可以有效地修复彩色图像中的块状损坏或缺失区域。 Criminisi算法是一种基于纹理合成的图像修复算法。该算法通过分析图像的纹理特征,将相似区域的纹理信息合成到修复区域中,从而使修复结果与原图像保持一致。Criminisi算法使用了一种叫做“exemplar-based”的纹理合成方法,通过在图像中选择合适的候选区域来填补损坏的区域,然后使用优化策略去调整纹理的连续性和一致性。该算法在彩色图像修复中广泛应用,可以有效地修复各种不同类型的损坏区域。 以上所提到的GUI FMM和Criminisi算法都有MATLAB码,可以通过下载1507期的压缩文件【MATLAB码 1507期】.zip获取。这些码可以帮助用户了解算法的具体实现细节,并通过自行修改和调整来实现对彩色图像修复。 ### 回答2: "FMM Criminisi算法"是一种用于彩色图像修复的算法。它可以通过修复有缺损的彩色图像,使其恢复原貌。 这份压缩包里包Matlab码,可以用于实现FMM Criminisi算法。首先,需要导入压缩包并解压码文件。在Matlab中运行码文件,可以查看图像修复的效果。 FMM Criminisi算法基于快速匈牙利算法(Fast Marching Method),是一种基于像素填充的图像修复算法。它通过分析图像中的缺损区域,找到最佳的填充像素来修复图像。 算法的核心思想是利用图像的局部特征和全局一致性来寻找最佳的填充像素。首先,需要确定缺损区域的边界,然后计算每个像素点到边界的距离。接着,根据距离和像素的相似性,选择最佳的像素进行填充。 FMM Criminisi算法的优点是能够处理复杂的缺损情况,并且能够保持图像的一致性和自然性。在修复过程中,它能够利用周围的像素信息来填补缺损区域,从而使修复后的图像与原图像相似。 使用这一Matlab码,我们可以根据需要进行图像修复实验。根据码的注释和参数设置,可以对图像进行不同的修复操作。通过反复尝试和调整参数,可以得到最佳的修复效果。 总之,这份压缩包中的FMM Criminisi算法的Matlab码可以帮助我们实现彩色图像修复修复后的图像将恢复到原始的状态。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Matlab领域

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

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

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

打赏作者

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

抵扣说明:

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

余额充值