How to perform stack operation of 4 shares in color images

1 view (last 30 days)
I have four shares, 3 shares corresponding to R,G and B and 1 share of black and white mask. To perform decryption in Visual cryptography I want to stack all these shares. Is there any operation to perform stacking of all four shares?

Answers (1)

Ayush
Ayush on 8 Jul 2024
Hi,
You can stack your four shares together. Take care that all four shares are of the same size. You can resize them if they are not. To stack them, you can make use of logical operations, where you can multiply your R, G, and B shares with the mask. I'm providing a sample implementation for better understanding; in the example, I have created a back and white mask with the message "img", and for R, G, and B share, I have synthetically generated with the help of the "uint8" function. Finally, I'm using logical operations by multiplying all the R, B, and G shares with the mask. Refer to the implementation code below:
% Create an image with the message "img"
message = 'img';
fontSize = 40;
image_size = [100, 100];
textImage = insertText(zeros(image_size), [10, 30], message, 'FontSize', fontSize, 'TextColor', 'white', 'BoxOpacity', 0);
textImage = rgb2gray(textImage); % Convert to grayscale
textImage = imbinarize(textImage); % Binarize the image
% Generate synthetic R, G, B shares based on the message
R = uint8(255 * rand(image_size)); % Random red share
G = uint8(255 * rand(image_size)); % Random green share
B = uint8(255 * rand(image_size)); % Random blue share
% Create the black and white mask based on the message
BW_mask = uint8(255 * textImage);
% Create color images for R, G, B shares
R_color = cat(3, R, zeros(image_size, 'uint8'), zeros(image_size, 'uint8')); % Red share as color image
G_color = cat(3, zeros(image_size, 'uint8'), G, zeros(image_size, 'uint8')); % Green share as color image
B_color = cat(3, zeros(image_size, 'uint8'), zeros(image_size, 'uint8'), B); % Blue share as color image
% Display the synthetic images
figure;
subplot(2,2,1), imshow(R_color), title('R Share');
subplot(2,2,2), imshow(G_color), title('G Share');
subplot(2,2,3), imshow(B_color), title('B Share');
subplot(2,2,4), imshow(BW_mask), title('Black and White Mask');
% Ensure all images are of the same size
assert(isequal(size(R), size(G), size(B), size(BW_mask)), 'All images must be of the same size');
% Create an output image
output_image = zeros([image_size, 3], 'uint8');
% Stack the shares using logical operations
output_image(:,:,1) = uint8(double(R) .* double(BW_mask) / 255); % Red channel
output_image(:,:,2) = uint8(double(G) .* double(BW_mask) / 255); % Green channel
output_image(:,:,3) = uint8(double(B) .* double(BW_mask) / 255); % Blue channel
% Display the result
figure;
imshow(output_image);
title('Decrypted Image with Message');
For more information on "uint8" function, refer to the below documentation:

Categories

Find more on Modify Image Colors in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!