Pls explain This Code Of Image Ecryption For me ???
显示 更早的评论
Hello Can Someone Explain the code for me ???
采纳的回答
更多回答(1 个)
Image Analyst
2014-8-9
If what Geoff says is true, I've done that for another post. See first hidden comment in this post. The code below will work for rectangular color images.

clc;
clearvars;
close all;
workspace;
fontSize = 16;
% Read in a color demo image.
folder = fileparts(which('cameraman.tif')); % Determine where demo folder is (works with all versions).
baseFileName = 'peppers.png';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')
% Didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
rgbImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = 3.
[rows, columns, numberOfColorBands] = size(rgbImage);
% Display the original color image.
subplot(2, 2, 1);
imshow(rgbImage);
title('Original Color Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Get the order to scramble them in
scrambleOrder = randperm(rows*columns);
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
% Scramble according to the scrambling order.
redChannel = redChannel(scrambleOrder);
greenChannel = greenChannel(scrambleOrder);
blueChannel = blueChannel(scrambleOrder);
% Reshape into a 2D image
redChannel = reshape(redChannel, [rows, columns]);
greenChannel = reshape(greenChannel, [rows, columns]);
blueChannel = reshape(blueChannel, [rows, columns]);
% Recombine separate color channels into a single, true color RGB image.
scrambledImage = cat(3, redChannel, greenChannel, blueChannel);
% Display the scrambled color image.
subplot(2, 2, 2);
imshow(scrambledImage);
title('Scrambled Color Image', 'FontSize', fontSize);
% Recover the image, knowing the sort order
recoverOrder = zeros([rows*columns], 2);
recoverOrder(:, 1) = 1 : (rows*columns);
recoverOrder(:, 2) = scrambleOrder;
% Sort this to find out where each scrambled location needs to be sent to.
newOrder = sortrows(recoverOrder, 2);
% Extract just column 1, which is the order we need.
newOrder = newOrder(:,1);
% Unscramble according to the recoverOrder order.
redChannel = redChannel(newOrder);
greenChannel = greenChannel(newOrder);
blueChannel = blueChannel(newOrder);
% Reshape into a 2D image
redChannel = reshape(redChannel, [rows, columns]);
greenChannel = reshape(greenChannel, [rows, columns]);
blueChannel = reshape(blueChannel, [rows, columns]);
% Recombine separate color channels into a single, true color RGB image.
scrambledImage = cat(3, redChannel, greenChannel, blueChannel);
% Display the original color image.
subplot(2, 2, 3);
imshow(scrambledImage);
title('Unscrambled Color Image', 'FontSize', fontSize);
13 个评论
mosarrat jahan
2016-10-20
HOW CAN I GET period fo iterations where they will restore the original image arnolcAT MAP
Walter Roberson
2016-10-20
You can either calculate it mathematically based on group theory, or you can run the iterations of the cat map in a loop, counting until the iteration brings you back to the original image.
lakshmi boddu
2018-2-2
i am working on a project "color image encryption based on chaotic maps" in which i first divide color image into rgb components and scramble each component using 2D arnold cat image ,can u please me with the code sir
Image Analyst
2018-2-2
All I have about Arnold's cat map is the attached m-file that I wrote. Adapt as needed. Good luck.
lakshmi boddu
2018-2-11
Thank you sir
OmarUs iSw!FT
2018-2-14
编辑:OmarUs iSw!FT
2018-2-14
Please sir, how can I recover the original image after a random number of iterations?
Image Analyst
2018-2-14
You can't. The original image will only be returned after a very specific number of runs. After a random number of runs, unless it's the number that works, you'll be left with a scrambled looking image. That's what it's supposed to do. You can't just run it any old random number of runs and have it look like the original, but you'll get it back eventually. Did you run my demo?
Walter Roberson
2018-2-15
"Please sir, how can I recover the original image after a random number of iterations?"
If the number of iterations is known, then it is possible to construct a reverse transform that recovers the original image in a single step.
If the number of iterations is not known, then you can take advantage of the fact that the chaotic manipulation of an image has a lot of sharp local contrasts and sharp color changes. So create a metric of how locally quickly a given version of the image is changing, and then proceed to put the image through another iteration and measure again -- and keep doing this until you are back at the image you were trying to decode. The version with the lowest measure of local disorder is probably the original image.
OmarUs iSw!FT
2018-2-15
Image Analyst, Thank you sir for your answer. actually, your code has been executed successfully.
My question is simple: Suppose we did 10 iterations on the original image (Lena for example) using the Arnold's cat Map. how we can return Lena from this scrambled image ?
OmarUs iSw!FT
2018-2-15
Walter Roberson, This is a good proposal. maybe I'll use correlation and entropy as metrics to evaluate the resemblance between the original image and the scrambled image. do you have any other suggestions about metrics?
Image Analyst
2018-2-15
You can keep running the code and using isequal(originalImage, scrambledImage) until it returns "true". Is that what you mean? Or, if you don't have the original image, run stdfilt() after each iteration and take the iteration where the std dev is min, like Walter suggested.
OmarUs iSw!FT
2018-2-15
编辑:OmarUs iSw!FT
2018-2-15
i want just the inverse function after N iterations to return the image original -> Simply, the inverse function of this :
N = rows;
oldScrambledImage = grayImage;
for row = 1 : rows % y
for col = 1 : columns % x
c = mod((2 * col) + row, N) + 1; % x coordinate
r = mod(col + row, N) + 1; % y coordinate
% Move the pixel. Note indexes are (row, column) = (y, x) NOT (x, y)!
currentScrambledImage(row, col, :) = oldScrambledImage(r, c, :);
end
end
Walter Roberson
2018-2-15
编辑:Walter Roberson
2018-2-15
I have outlined code to decode cat map in the past, if the number of iterations is given.
You create an "image" in which each location holds a value which is the linear index of the location. Put that through the known number of iterations of cat map. The result is a template for where each location moves. Now you can use
Recovered(Template) = Scrambled ;
and each pixel in Scrambled will be moved back to its proper location.
类别
在 帮助中心 和 File Exchange 中查找有关 Image Transforms 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!