Help uncovering an image

1 view (last 30 days)
Grace
Grace on 2 Mar 2014
Commented: Image Analyst on 3 Mar 2014
An image has been purposely modified in an attempt to conceal a hidden image. First the pixel values were all divided by 10, so the range of the data was reduced to 0 to 26. Then the value 200 was added to about half of the pixels which were selected at random. This processing covers the original image with random noise, however, it is possible to remove the processing and recover the original image. The pixels that were randomly selected will have values greater than 26, so in order to recover the original image, a program needs to check each pixel value, and for those pixels that have a value greater than 26, the program should subtract 200. Then the program should multiply all pixel values by 10. Write a script file that loads secret_image.bmp, recovers the original image, and displays the result.
This is the best I have got. help would be appreciates
I = imread('secret_image.bmp');
for m=1:length(I(1,:))
for n=1:length(I(:,1))
if (I(m,n)>26)
J=((I(m,n))-200)*10;
I(m,n)=J;
end
end
end
figure(1)
imshow(I)

Answers (2)

Walter Roberson
Walter Roberson on 2 Mar 2014
all pixels need to be multiplied by 10, not just the ones that were above 26.

Image Analyst
Image Analyst on 2 Mar 2014
Edited: Image Analyst on 2 Mar 2014
See this demo:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures if you have the Image Processing Toolbox.
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 25;
% Check that user has the Image Processing Toolbox installed.
hasIPT = license('test', 'image_toolbox');
if ~hasIPT
% User does not have the toolbox installed.
message = sprintf('Sorry, but you do not seem to have the Image Processing Toolbox.\nDo you want to try to continue anyway?');
reply = questdlg(message, 'Toolbox missing', 'Yes', 'No', 'Yes');
if strcmpi(reply, 'No')
% User said No, so exit.
return;
end
end
% Read in a standard MATLAB gray scale demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
button = menu('Use which demo image?', 'CameraMan', 'Moon', 'Eight', 'Coins', 'Pout');
if button == 1
baseFileName = 'cameraman.tif';
elseif button == 2
baseFileName = 'moon.tif';
elseif button == 3
baseFileName = 'eight.tif';
elseif button == 4
baseFileName = 'coins.png';
else
baseFileName = 'pout.tif';
end
% Read in a standard MATLAB gray scale demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% File doesn't exist -- didn't find it there. Check the search path for it.
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.
% numberOfColorBands should be = 1.
[rows, columns, numberOfColorBands] = size(grayImage);
if numberOfColorBands > 1
% It's not really gray scale like we expected - it's color.
% Convert it to gray scale by taking only the green channel.
grayImage = grayImage(:, :, 2); % Take green channel.
end
% Display the original gray scale image.
subplot(2, 2, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
% Divide by 10
grayImage2 = double(grayImage) / 10;
% Find pixels to add 200 to
numPixels = rows*columns;
randomPixels = randperm(numPixels, int32(numPixels/2));
grayImage2(randomPixels) = grayImage2(randomPixels) + 200;
% Display the image.
subplot(2, 2, 2);
imshow(grayImage2, []);
title('Secret Image', 'FontSize', fontSize);
% Now recover.
% Find pixels greater than 200
brightPixels = grayImage2 >= 200;
recoveredImage = grayImage2; % Initialize
recoveredImage(brightPixels) = recoveredImage(brightPixels) - 200; % Now 200 has been subtracted.
% Now multiply by 10
recoveredImage = uint8(10 * recoveredImage);
% Display the image.
subplot(2, 2, 3);
imshow(recoveredImage, []);
title('Recovered Image', 'FontSize', fontSize);
  4 Comments
Grace
Grace on 3 Mar 2014
thanks for your help but the programming I have learnt so far is pretty basic, so I haven't learnt a lot of the terms you are using. I am supposed to use loops, I am just trying to find out what is wrong with my code
Image Analyst
Image Analyst on 3 Mar 2014
Well first of all your image is color, not grayscale because it is 3 dimensional. So call rgb2gray right after you read it in from disk with imread. Then you need to do
[rows, columns, numberOfColorChannels] = size(I);
if numberOfColorChannels > 1
I = rgb2gray(I);
end
for n=1:columns
for m=1:rows
instead of what you used.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!