MATLAB Answers

could anybody tell me how to fix this image?

7 views (last 30 days)
Omar Zoheir
Omar Zoheir on 14 Aug 2020
Commented: Rena Berman on 12 Oct 2020 at 17:24


Image Analyst
Image Analyst on 15 Aug 2020
Original question:
could anybody tell me how to fix this image?
Rena Berman
Rena Berman on 12 Oct 2020 at 17:24
(Answers Dev) Restored edit

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 14 Aug 2020
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;
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);
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.
% Display the image.
subplot(2, 2, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize, 'Interpreter', 'None');
hFig = gcf;
hFig.WindowState = 'maximized'; % May not work in earlier versions of MATLAB.
% Display histogram
subplot(2, 2, 2);
grid on;
title('Histogram of original gray image', 'FontSize', fontSize);
windowWidth = 8;
kernel = ones(windowWidth)/windowWidth^2;
b = uint8(conv2(double(grayImage), kernel, 'valid'));
subplot(2, 2, 3:4);
imshow(imadjust(b), []);
title('Filtered Image', 'FontSize', fontSize, 'Interpreter', 'None');


Sign in to comment.

Community Treasure Hunt

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

Start Hunting!