Seeking Help with MATLAB Image Restoration

10 views (last 30 days)
wei-kai
wei-kai on 21 Jul 2023
Answered: Image Analyst on 21 Jul 2023
I hope this message finds you all well. I am currently working on an image processing project and could use some guidance from the talented minds in this community.
The project involves restoring 100 blurred images that were impacted by a slight oil smudge on the camera lens. As an enthusiast in image processing, this presents an excellent opportunity for me to enhance my skills in image deblurring and restoration.
I have already started the restoration process using MATLAB; however, I am facing challenges in preserving the original colors of the images after applying deblurring techniques.
If any of you have experience in image deblurring or have encountered similar challenges, I would be incredibly grateful for any insights, tips, or guidance you can provide. Additionally, if you are aware of useful resources, tutorials, or MATLAB functions specifically related to image restoration, your recommendations would be invaluable.
Here is my current code for the image restoration process:
% Set the folder path, here it is assumed that the photo folder is in the 7.18 study photo folder on the desktop
folder_path = 'C:\Users\pc\Desktop\7.18 study photos\';
% read all files in the folder
file_list = dir(fullfile(folder_path, '*.jpg')); % It is assumed that the file extension of the photo is .jpg, which can be adjusted according to the actual situation
% process each photo
for i = 1:length(file_list)
% read image
image_path = fullfile(folder_path, file_list(i).name);
image = imread(image_path);
% blur removal
psf = fspecial('gaussian', [5 5], 2); % assume Gaussian blur
noise_var = 0.01; % Assumed noise variance
deblurred_image = deconvwnr(image, psf, noise_var);
% Convert deblurred image to grayscale image
gray_image = rgb2gray(deblurred_image);
% Stain removal treatment
threshold = 0.2; % Assuming the threshold is 0.2, it can be adjusted according to demand
mask = gray_image < threshold;
clean_image = gray_image;
clean_image(mask) = medfilt2(gray_image, [3 3]); % assume a 3x3 median filter
% Save the processed image back to the original file
imwrite(clean_image, image_path);
end
disp('All photos are processed.');
I am confident that the combined knowledge and expertise of the MATLAB community can offer valuable support and help me overcome these challenges successfully.
Thank you for your time, and I eagerly anticipate your valuable advice and suggestions.

Answers (1)

Image Analyst
Image Analyst on 21 Jul 2023
I doubt this will work
clean_image = gray_image;
clean_image(mask) = medfilt2(gray_image, [3 3]); % assume a 3x3 median filter
You should try it this way
clean_image = gray_image;
filtered_image = medfilt2(gray_image, [3 3]); % assume a 3x3 median filter
% Replace pixels, but only in the mask, with the median filtered values.
clean_image(mask) = filtered_image(mask);
Other than that, who knows, since you didn't post your image. It might work but only Walter has the crystal ball toolbox and can see your images. I don't. So you'll have to wait for him if you don't want to post an image.

Products


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!