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

DGM
DGM 2022년 1월 5일
편집: DGM 2022년 1월 5일
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?

댓글을 달려면 로그인하십시오.

 채택된 답변

Walter Roberson
Walter Roberson 2022년 1월 2일
편집: Walter Roberson 2022년 1월 2일

1 개 추천

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

Obaid Ullah
Obaid Ullah 2022년 1월 4일
The image is so blur. Why?
Walter Roberson
Walter Roberson 2022년 1월 4일
편집: Walter Roberson 2022년 1월 4일
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.
Obaid Ullah
Obaid Ullah 2022년 1월 4일
But its not working on MATLAB
Walter Roberson
Walter Roberson 2022년 1월 4일
?? I show exact code and output. It is working in MATLAB, at least for grayscale images. For rgb you would need convn()
Obaid Ullah
Obaid Ullah 2022년 1월 5일
yes, i was using rgb image.
Obaid Ullah
Obaid Ullah 2022년 1월 5일
My code is not convolving with your code
DGM
DGM 2022년 1월 5일
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')
Obaid Ullah
Obaid Ullah 2022년 1월 8일
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.
DGM
DGM 2022년 1월 8일
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 2022년 1월 8일
편집: Walter Roberson 2022년 1월 8일
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 2022년 1월 21일
편집: Walter Roberson 2022년 1월 21일
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
Obaid Ullah
Obaid Ullah 2022년 1월 22일
kindly provide for black and white image
Walter Roberson
Walter Roberson 2022년 1월 22일
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
Walter Roberson
Walter Roberson 2022년 1월 25일
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.
Obaid Ullah
Obaid Ullah 2022년 1월 25일
Thanks for the help...

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

질문:

2022년 1월 2일

댓글:

2022년 1월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by