how to make a face image scramble by matlab?

I want to scramble a grayscale image and actually I want to have patches or square blocks and scramble by them. But before that I have to mask my image by an oval then scramble the part of image that is inside of oval, for this reason I have to make vertical and horizental strips in that oval and scramble them. Also I prefer to have ability to change size of this strips. Would you please help me by that?
I have this image:
(mary.BW)and I mask it by oval by this code:
----------------------------------------
clear all Baselum=0; Radius=342;
X=206 Y1=78; Y2=323;
for c=1
I=imread(['C:\Users\User\Desktop\oval mask\attached image.jpg']);
for i=1:400
for j=1:400
ovaldistance=(sqrt((X-i)^2 + (Y1-j)^2)+sqrt((X-i)^2 + (Y2-j)^2));
if ovaldistance > Radius
I(j,i,:)=Baselum;
end;
end;
end;
imwrite(I,['OvalMask1','attached image.jpg']);
end;
----------------------------------------
and the result will be like this:
(oval mask.jpg)
and now I want to scramble part of image that is in the oval. I have to make strips and flip them in order to make the image scrambled. But I don't know the right matlab function to do it. Please Help me. The result must be something like the third attached image:
Pleaaaaaasee help meeeeeeee

 Accepted Answer

That's not scrambling. it's just an inefficient way of doing masking (inefficient because you create the mask for every pixel and call randperm when you don't have to). There are lots of ways to scramble. How do you want to do it? Do you just want to use randperm to send each pixel to a new location?

6 Comments

If you do want to do that, try this:
clc;
clearvars;
close all;
workspace;
fontSize = 16;
% Read in a color demo image.
folder = 'C:\Users\User\Documents\Temporary';
baseFileName = 'mary.jpg';
% 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);
many thanks but it is not my mentioned scrambling, I want to scramble graysclae image and actually I want to have patches or square blocks and scramble by them. But befor that I have to mask my image by an oval then scramble the part of image that is inside of oval, for this reason I have to make vertical and horizental strips in that oval and scramble them. Also I prefer to have ability to change size of this strips. Would you please help me by that?
I have this image:
(mary.BW)and I mask it by oval by this code:
---------------------------- clear all Baselum=0; Radius=342;
X=206 Y1=78; Y2=323;
for c=1
I=imread(['C:\Users\User\Desktop\oval mask\attached image.jpg']);
for i=1:400
for j=1:400
ovaldistance=(sqrt((X-i)^2 + (Y1-j)^2)+sqrt((X-i)^2 + (Y2-j)^2));
if ovaldistance > Radius
I(j,i,:)=Baselum;
end;
end;
end;
imwrite(I,['OvalMask1','attached image.jpg']);
end;
----------------------------------------
and the result will be like this:
(oval mask.jpg)
and now I want to scramble part of image that is in the oval. I have to make strips and flip them in order to make the image scrambled. But I don't know the right matlab function to do it. Please Help me. The result must be something like the third attached image:
please tell me how can I make vertical and horizental strips with special sizes and flip them?
many thanks, would you please tell me how can I make strips(vertical and horizental) on an image?
YourImage(:,32:32:end,:) = 0;
would set the pixels to black every 32'nd column.

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!