Error in the function

조회 수: 15 (최근 30일)
Anca Chivulescu
Anca Chivulescu 2021년 6월 7일
댓글: Anca Chivulescu 2021년 6월 9일
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
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일
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월 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개)

카테고리

Help CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by