hello! I'm having a litle trouble while running my code. I've hidden a text document behind a picture and i wish by decoding it to be able to see the hideen text. Somehow it seems something is not right because it apears in the matlab workspace in a vector form. is it posible to see the initial text? i've used the ASCII code...
my code
I=imread('im1.png');
function [dec_text]=decodare_txtf(I)
[row, col] = size(I);
dec_text = zeros(1, row);
pas = col/4;
for i = 1 : row
aux = 0;
aux = uint8(aux);
for j = 1:4
aux = aux * 2^2;
aux = aux + mod(I(i,j*pas), 2^2);
end
dec_text(i) = char(aux);
end
text = char(dec_text);
A = mat2str(text);
imshow('im1.png'),title('Imagine decodata');
disp(A);
end
i've attached the files in question.

4 件のコメント

KSSV
KSSV 2021 年 6 月 7 日
Wht error you are getting?
Anca Chivulescu
Anca Chivulescu 2021 年 6 月 7 日
i don't know if the text mesage has to be in that form, lots of numbers from 0 to 255 randomnly placed, or have to do something else to be able to see the text whit the original content. or is a line i forgot to put somewhere and that is why i can't see the text. i've attached the results. is this how it has to be?
Walter Roberson
Walter Roberson 2021 年 6 月 7 日
After you assign the imread to I, you need to make a call to the function. Matlab does not not assume that the function should be called just because it is present in the file.
Anca Chivulescu
Anca Chivulescu 2021 年 6 月 7 日
Thank you!

サインインしてコメントする。

 採用された回答

KSSV
KSSV 2021 年 6 月 7 日

0 投票

You need to save the below code into a function named: decodare_txtf.m in some folder.
function [dec_text]=decodare_txtf(I)
[row, col] = size(I);
dec_text = zeros(1, row);
pas = col/4;
for i = 1 : row
aux = 0;
aux = uint8(aux);
for j = 1:4
aux = aux * 2^2;
aux = aux + mod(I(i,j*pas), 2^2);
end
dec_text(i) = char(aux);
end
text = char(dec_text);
A = mat2str(text);
imshow('im1.png'),title('Imagine decodata');
disp(A);
end
After saving the function, you should add it's path or make that folder as present working directory and call the function.
I=imread('im1.png');
[dec_text]=decodare_txtf(I) ;

10 件のコメント

Anca Chivulescu
Anca Chivulescu 2021 年 6 月 7 日
Thank you!
KSSV
KSSV 2021 年 6 月 7 日
Thanks is accepting or voting the answer... ;)
Anca Chivulescu
Anca Chivulescu 2021 年 6 月 8 日
I want to! But how? I can't find the option to do that
Anca Chivulescu
Anca Chivulescu 2021 年 6 月 8 日
Done!
Anca Chivulescu
Anca Chivulescu 2021 年 6 月 8 日
編集済み: Walter Roberson 2021 年 6 月 8 日
Whit the same code, how can i make it to show me the full text? it's showing me only the first 128 characters. Where do i make the mistake? I have to recal the code again? And i deleted the function.
Now the code is this
I=imread('somename.png');
[row ,col] = size(I);
dec_text = zeros(1, row);
pas = col/4;
for i = 1 : row
aux = 0;
aux = uint8(aux);
for j = 1:4
aux = aux * 2^2;
aux = aux + mod(I(i,j*pas), 2^2);
end
dec_text(i) = char(aux);
end
dec_text = char(dec_text);
disp(dec_text);
Walter Roberson
Walter Roberson 2021 年 6 月 8 日
Is your image possibly 128 rows high? Your code creates one entry in dec_text for each row of I.
Anca Chivulescu
Anca Chivulescu 2021 年 6 月 8 日
Yes. It has 128 rows and colums... Is that why? Do i need to modiffy the size?
Walter Roberson
Walter Roberson 2021 年 6 月 8 日
For each row, the code takes the last column in each "quarter", and uses 2 bits from it, building up to a total of 4*2 = 8 bits for each row. With 128 rows, that gives you 128 entries.
Your text file, 1.txt, is not used in any way by the code you posted.
Perhaps the code is intended to be the decoding portion. If so, then the way it is constructed assumes that you encode exactly 8 bits per row, so if you have more than 128 characters, you would need a larger image with more rows. Or you would need to change the way the data was hidden.
Anca Chivulescu
Anca Chivulescu 2021 年 6 月 8 日
Thank you so very much!
Anca Chivulescu
Anca Chivulescu 2021 年 6 月 9 日
I've changed both the text length and image size. 1024/1024 and it worked. Thank you for your help!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeConvert Image Type についてさらに検索

製品

リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by