I have an encrypted image,I wantit to like these so I can be able to test for data loss

7 Comments

Jan
Jan on 15 Oct 2022
"I wantit to like these" - this is not sufficient to clearify, what you want to achieve. Which details matter? What are the inputs? What have you tried so far? which Matlab realted problems did occur?
Hello. The image is encrypted,I have managed to recover the image to its original form when I applied salt&pepper noise,speckle noise and Poisson noise. Then assume there is about 25% of data loss(black area) as shown in the picture or whatever %. What are the MATLAB codes I can use to plot that black area?
@dani elias: "The image is encrypted,I have managed to recover the image to its original form when I applied salt&pepper noise,speckle noise and Poisson noise." - you procide information, which does not have a relation to the problem, but important details, which would clarify the problem are still missing.
What are your inputs? "Encrypted images" is less clear than: uint8 RGB arrays? uint16 grayscale matrices? logical binary matrices?
Do you want to plot the black area? Then it is visible on the screen. I assume you want to set a square (or almost square, 25% need not be an integer) block of data to 0 (not "black")?
Then a compact and exhaustive version of your question would be:
data = randi([0, 255], 400, 400, 'uint8');
How to set an almost square block in the center to 0, which occupies X% of the pixels?
Sorry for my bad explanation,but after read your comments now I can explain in a better way. assume you have a square image uint8, gray-scale. I want to insert a rectangle (we refer this as data loss in terms of % covered). For example
A=imread('jojo.bmp');
A=insertShape(A,'filledrectangle',[15 28 75 65],'Color',{black},Opacity=0.7);
Figure,imshow(A);
Here,I insertes rectangle using coordinates.is there any means of covering the image using rectangle in % form? (for example 25% is covered,or 10% is covered) How can I do that?
No, MATLAB does not provide any functions that alter arrays based upon percentage sizes. You will need to take size() of the rectangle and multiply by the fraction to arrive at the target sizes.
Thank you
Jan
Jan on 16 Oct 2022
Remember that insertShape replies an RGB image.

Sign in to comment.

 Accepted Answer

Try this on your recovered image
% Create "recovered" image.
grayImage = imread('cameraman.tif');
grayImage = imnoise(grayImage, "gaussian", 0, .01);
[rows, columns, numberOfColorChannels] = size(grayImage)
rows = 256
columns = 256
numberOfColorChannels = 1
subplot(2, 1, 1);
imshow(grayImage, []);
title('Initial Image')
% Define fraction of pixels to blacken in the middle.
pct = 0.25;
% Determine how many pixels that is.
numBlackPixels = pct * numel(grayImage)
numBlackPixels = 16384
% Assume it's a square and determine the width of the square
squareWidth = sqrt(numBlackPixels)
squareWidth = 128
% Get the rows of the square in the original image
row1 = round(rows/2 - squareWidth/2)
row1 = 64
row2 = round(rows/2 + squareWidth/2)
row2 = 192
% Get the columns of the square in the original image
col1 = round(columns/2 - squareWidth/2)
col1 = 64
col2 = round(columns/2 + squareWidth/2)
col2 = 192
% Do the blackening:
grayImage2 = grayImage; % Initialize
grayImage2(row1:row2, col1:col2) = 0; % Blacken square in the middle
subplot(2, 1, 2);
imshow(grayImage2, [])
title('Output Image')

More Answers (0)

Community Treasure Hunt

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

Start Hunting!