could anybody tell me how to fix this image?

2 次查看(过去 30 天)

回答(1 个)

Image Analyst
Image Analyst 2020-8-14
Is it corrupted, or is it just a raw, mosaiced image? If it got corrupted, do you know how it got corrupted? What gives the illusion of an image - is it the gray levels of the squares, or a slightly size difference in the squares?
There are bad jpeg artifacts in that image. Do you have the original in a lossless format like TIFF, PNG, or BMP? JPG is the worst when it comes to image processing.
Also, you forgot to list what release you're using. You can do that now over on the right hand side of this page.
Here is one way to improve it:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 22;
%--------------------------------------------------------------------------------------------------------
% READ IN IMAGE
folder = pwd;
baseFileName = 'image.jpeg';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% The file doesn't exist -- didn't find it there in that folder.
% Check the entire search path (other folders) for the file by stripping off the folder.
fullFileNameOnSearchPath = baseFileName; % No path this time.
if ~exist(fullFileNameOnSearchPath, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = imread(fullFileName);
% Get the dimensions of the image.
% numberOfColorChannels should be = 1 for a gray scale image, and 3 for an RGB color image.
[rows, columns, numberOfColorChannels] = size(grayImage);
if numberOfColorChannels > 1
% It's not really gray scale like we expected - it's color.
% Use weighted sum of ALL channels to create a gray scale image.
grayImage = rgb2gray(grayImage);
% ALTERNATE METHOD: Convert it to gray scale by taking only the green channel,
% which in a typical snapshot will be the least noisy channel.
% grayImage = grayImage(:, :, 2); % Take green channel.
end
% Display the image.
subplot(2, 2, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize, 'Interpreter', 'None');
impixelinfo;
hFig = gcf;
hFig.WindowState = 'maximized'; % May not work in earlier versions of MATLAB.
drawnow;
% Display histogram
subplot(2, 2, 2);
imhist(grayImage);
grid on;
title('Histogram of original gray image', 'FontSize', fontSize);
%--------------------------------------------------------------------------------------------------------
% FILTRATION OF IMAGE
windowWidth = 8;
kernel = ones(windowWidth)/windowWidth^2;
b = uint8(conv2(double(grayImage), kernel, 'valid'));
subplot(2, 2, 3:4);
imshow(imadjust(b), []);
impixelinfo;
title('Filtered Image', 'FontSize', fontSize, 'Interpreter', 'None');
impixelinfo;
  1 个评论
Francisco Molano
Francisco Molano 2023-3-29
yes, i had tired with this code to get that image fixed, more code to go for 4k resolutions. so awsome to tried this out.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by