I am working on steganography, using morse code method. I want to convolve my output with image so that my info got hidden and then again retrieve my hidden code from image and display it.
clc
load data.mat
in_text = 'let''s decode';
fprintf('Input : %s\n', in_text);
text= lower(in_text);
len = length(text);
mor = [];
for i=1:len
if text(i)== ' '
mor = [mor '/'];
elseif isvarname(text(i))
mor = [mor getfield(morse,text(i))];
mor = [mor ' '];
elseif ~isempty(str2num(text(i)))
mor = [mor getfield(morse,[ 'n',text(i)])];
mor = [mor ' '];
elseif findstr(text(i),morse.sc)
mor = [ mor char(morse.scv(findstr(text(i),morse.sc)))];
mor = [mor ' '];
end
end
fprintf('Output : %s\n',mor);
%%decode
code = mor;
deco = [];
code = [code ' '];
lcode =[];
for j=1:length(code)
if(strcmp(code(j),' ')|strcmp(code(j),'/'))
for i=double('a'):double('z')
letter = getfield(morse,char(i));
if strcmp(lcode,letter)
deco = [deco char(i)];
end
end
for i= 0:9
numb = getfield(morse,['n',num2str(i)]);
if strcmp(lcode,numb)
deco = [deco,num2str(i)];
end
end
for i=1:4
scv=char(morse.scv(i));
if strcmp(lcode,scv)
deco = [deco, morse.sc(i)];
end
end
lcode = [];
else
lcode = [lcode code(j)];
end
if strcmp(code(j),'/')
deco = [deco ' '];
end
end
fprintf('Decoded : %s\n',deco);

1 Comment

DGM
DGM on 5 Jan 2022
Edited: DGM on 5 Jan 2022
Without knowing the details of what got loaded into the workspace
load data.mat
or what otherwise undefined things like 'morse' are, it's difficult to know what exactly is supposed to be happening here.
Is this all just table lookup with a bunch of loose named variables instead of a lookup table?
What is convolution of a char vector and an image supposed to do? It will result in a blurred, out-of-scale image. Since that's not likely intended, what is intended?

Sign in to comment.

 Accepted Answer

mor = '.... .- .--. .--. -.-- / -. . .-- / -.-- . .- .-. -.-.--';
mord = im2double(uint8(mor));
img = im2double(imread('cameraman.tif'));
cimg = conv2(img, mord, 'same');
cimg8 = im2uint8(cimg);
imshow(img);
title('cameraman')
imshow(cimg8)
title('convolved')
[min(cimg(:)), max(cimg(:))]
ans = 1×2
0.4090 6.8147
imshow(cimg, [])
title('convolved, rescaled')

20 Comments

The image is so blur. Why?
Walter Roberson
Walter Roberson on 4 Jan 2022
Edited: Walter Roberson on 4 Jan 2022
This is what convolution does.
Suppose that you wanted to create an audio echo by taking the current sample and adding 1/10 of the input from 5 samples previous. You could imagine creating a vector [1 0 0 0 0 1/10] as a specification for the operation you wanted to do: 1 times the current sample, plus 0 times the four most recent before that, plus 1/10 of the sample before that. You can see that by choosing a sample rate you could arrange a model of a complicated room echo with varying delays and echo strengths. It could be a convenient way to represent a filter process, if such a representation existed.
It turns out that it does exist... and it is what is implemented by conv(). Discrete convolution is essentially a filter process in which each entry in the vector specifies how much echo to use of the samples from how long before. Discrete convolution with [0 0 1] is effectively a delay by two samples. Discrete convolution with [1 -1]/Fs is effectively derivative where Fs is the sample time. So you can do echo, delay, derivative all with conv() and choice of vector.
Now choose a vector in which every entry has value 45, 46, or 47, and let it be (say) 30 elements long. No negative coefficients and no leading zero, so this specifies a series of echos. In the context of an image, this would blur each pixel over a width of (in this case) 30, by amounts that are almost but not exactly all the same. 45 times the pixel 29 back plus 47 times the pixel 28 back plus... and so on to 45, 46, or 47 times the current pixel. The effect is going to be close to what you would get if you took the sum of the 30 adjacent pixels and multiplied by 46, but not exactly that. Everything smeared 30 (in this example) pixels across.
Why 45, 46, 47? Well it happens that the internal code for the dash character is 45, and for dot is 46, and for / is 47. When you create your vector of dash, dot, and slash representing the Morse code message, the internal representation is a vector of 45, 46, or 47, and the length of the vector is the length of your encoded message.
So... when you asked to convolve the image with the Morse code text, this is exactly what you were asking for, smearing the image.
But its not working on MATLAB
?? I show exact code and output. It is working in MATLAB, at least for grayscale images. For rgb you would need convn()
yes, i was using rgb image.
My code is not convolving with your code
Nobody can know why your code doesn't do what you want unless you show your code and clearly describe what you expect it to do.
mor = '.... .- .--. .--. -.-- / -. . .-- / -.-- . .- .-. -.-.--';
mord = im2double(uint8(mor));
img = im2double(imread('flamingos.jpg'));
cimg = convn(img, mord, 'same');
cimg8 = im2uint8(cimg);
imshow(img);
title('flamingos')
imshow(cimg8)
title('convolved')
[min(cimg(:)), max(cimg(:))]
ans = 1×2
0.2539 9.2497
cr = rescale(cimg);
imshow(cr)
title('convolved, rescaled')
I have shown the code above. I want to convolve my encoded morse code with image ( hide my morse code in image) and then decode my morse code to get my hidden data (morse code) through image.
We're still at square one. See my comment above.
The code you posted can't be run by anyone else, as it is incomplete. We can only assume that what it does is plaintext to morse code conversion. The result is still a character vector. You have not provided any clarification.
The result of naive convolution has been demonstrated. Since that's clearly not what you want, you have to formally describe what you actually do want. Is there a particular established algorithm which you are trying to implement?
Walter Roberson
Walter Roberson on 8 Jan 2022
Edited: Walter Roberson on 8 Jan 2022
Note that "convolve" has a specific mathematical definition (which is closely related to a kind of filter being slid across the array.)
I suspect that you do not want convolution. I suspect that you want something like replicating the Morse to be the same as the number of pixels and then storing the Morse in the least significant bits... or something similar.
Obaid Ullah
Obaid Ullah on 21 Jan 2022
Edited: Walter Roberson on 21 Jan 2022
Could you perform deconvolution for this code you have given above.
format long g
mor = '.... .- .--. .--. -.-- / -. . .-- / -.-- . .- .-. -.-.--';
mord = im2double(uint8(mor));
img = im2double(imread('flamingos.jpg'));
cimg = convn(img, mord, 'same');
cimgfull = convn(img, mord);
cimg8 = im2uint8(cimg);
cimgfull8 = im2uint8(cimgfull);
imshow(img);
title('flamingos')
imshow(cimg8)
title('convolved')
imshow(cimgfull8)
title('convolved and not clipped')
[min(cimg(:)), max(cimg(:))]
ans = 1×2
0.253902345251826 9.24973471741637
cr = rescale(cimg);
imshow(cr)
title('convolved, rescaled')
[min(cimgfull(:)), max(cimgfull(:))]
ans = 1×2
0 9.24973471741637
crfull = rescale(cimgfull);
imshow(crfull)
title('convolved, rescaled, not clipped')
dcimgfull = DeconvImgr(cimgfull, mord);
[min(dcimgfull(:)), max(dcimgfull(:))]
ans = 1×2
1.0e+00 * -298774.96884186 280906.915147815
imshow(dcimgfull);
title('deconvolved, rescaled, not clipped');
function dc = DeconvImgr(im, key)
for p = size(im,3) : -1 : 1
for r = size(im,1) : -1 : 1
dc(r, :, p) = deconv(im(r,:,p), key);
end
end
end
kindly provide for black and white image
The only change in the code for a black and white image would be the filename for the imread(). And the title() could be updated to match I suppose.
The code would have to be changed a little if it was a pseudocolor image such as a GIF.
mor = '.-.. . - -.-.-.- ... /-.. . -.-. --- -.. .';
mord = im2double(uint8(mor));
img = im2double(imread('mini convolved.jpg'));
cimg = convn(img, mord, 'same');
cimg8 = im2uint8(cimg);
imshow(img);
title('cameraman')
imshow(cimg8);
title('convolved')
[min(cimg(:)), max(cimg(:))]
imshow(cimg, [])
title('convolved, rescaled')
kindly deconvolve this.......
The image attached is convolved (morse code convolved with image).
cimg = convn(img, mord, 'same');
No, in order to be able to do deconvolution, you need the full result of convolution, not the 'same' version.
format long g
mor = '.-.. . - -.-.-.- ... /-.. . -.-. --- -.. .';
mord = im2double(uint8(mor));
img = im2double(imread('cameraman.tif'));
cimg = convn(img, mord, 'same');
cimgfull = convn(img, mord);
cimg8 = im2uint8(cimg);
cimgfull8 = im2uint8(cimgfull);
imshow(img);
title('cameraman')
imshow(cimg8)
title('convolved')
imshow(cimgfull8)
title('convolved and not clipped')
[min(cimg(:)), max(cimg(:))]
ans = 1×2
0.236370626682045 5.1602614379085
cr = rescale(cimg);
imshow(cr)
title('convolved, rescaled')
[min(cimgfull(:)), max(cimgfull(:))]
ans = 1×2
0.0169780853517878 5.1602614379085
crfull = rescale(cimgfull);
imshow(crfull)
title('convolved, rescaled, not clipped')
dcimg = DeconvImgr(cimg, mord);
[min(dcimg(:)), max(dcimg(:))]
ans = 1×2
1.0e+00 * -8162033116.59736 9065670652.05357
imshow(dcimg)
title('deconvolved, rescaled, clipped')
dcimgfull = DeconvImgr(cimgfull, mord);
[min(dcimgfull(:)), max(dcimgfull(:))]
ans = 1×2
0.0274509803919202 0.992156862730571
imshow(dcimgfull);
title('deconvolved, rescaled, not clipped');
function dc = DeconvImgr(im, key)
for p = size(im,3) : -1 : 1
for r = size(im,1) : -1 : 1
dc(r, :, p) = deconv(im(r,:,p), key);
end
end
end
Notice that the data range for dcimg (Deconvolved version of convn() with 'same' option) is about +/- 1e11 whereas the data range for dcimgfull (Deconvolved version of conv() without 'same' option) is about 0 to 1.
Imagine that you multiply together two six-digit numbers; the result would normally be anywhere from 6 to 12 digits. But suppose you say, "Oh, get rid of everything except the last 6 digits of the result, because it is more convenient to me to have the result the same size as the original numbers." And then you take the clipped result and divide by one of the numbers, and you expect to get out the other number in full, and you are surprised when it does not work. But of course you need to keep all of the digits of the result of the multiplication in order for the division to work properly.
Thanks for the help...

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!