In the attached document, Im really stuck on what its asking. Could someone please help me better understand it, and what it wants me to do. I would really appreciate that, Thanks! Confused on the the last two parts. I dont know what code to use for the for loop to run through the rows and columns of the difference.
This is all I got so far.
pic=imread('Cat.png')
pic1=imread('CodedCat.png')
origpic=double(pic)
cpic=double(pic1)
[nrow ncol]=size(origpic)
Difference=ab(pic-cpic)

 채택된 답변

Guillaume
Guillaume 2015년 11월 21일

1 개 추천

Note that the decoding can be achieved much more efficiently with these three lines of codes:
cat = double(imread('Cat.png'));
codedcat = double(imread('CodedCat.png'));
message = char(bin2dec(char(reshape(abs(cat - codedcat)' == 1, 8, [])' + '0'))');
This is probably even more efficient since there's no number -> char -> number conversion to compute the ascii code of each character:
message = char(sum(bsxfun(@times, reshape(abs(cat - codedcat)' == 1, 8, []), 2 .^ (7:-1:0)')));

추가 답변 (1개)

Image Analyst
Image Analyst 2015년 11월 20일

0 개 추천

That's the most inefficient order - columns in the inner for loop and rows in the outer for loop, but anyway, since that is what you were told to do
[rows, columns, numberOfColorChannels]=size(origpic);
Difference = abs(origpic - cpic);
bin_message = zeros(1, rows*columns);
n=1;
for row = 1 : rows
for col = 1 : columns
if Difference(row, column) == 1
bin_message(n) = 1;
n = n + 1;
end
end
end
If you don't even know how to do a for loop, then you'd better read the "Getting Started" section of the help or read this link.

댓글 수: 6

Thanks, i really appreciate your help. I totally forgot about the bin message. One more thing, could you explain exactly what this section of code is supposed to do in the document. Thanks
message(1) = char(bin2dec(bin_message(1:8)))
message(2) = char(bin2dec(bin_message(9:16)))
Image Analyst
Image Analyst 2015년 11월 20일
It looks like it expects to build up an ASCII code for the character and that turns it into a letter. For example 1000001 = 65 = 'A'.
Brian Tiffman
Brian Tiffman 2015년 11월 21일
Ok so I need to put that into a for loop, right. Their going to be in binary, so would I want to use a double command inside of the for loop to get them into number values, and then turn them back into the original message.
Image Analyst
Image Analyst 2015년 11월 21일
bin_message is built up pixel by pixel apparently, so it will have as many elements as your image - possibly a million unless you know that your message ends earlier. So, after the double for loop, you have to extract the letters by moving along bin_message in 8 element blocks.
Note that the loops are absolutely not needed in the first place. It's a shame that the assignment require them.
Also not needed is the if. The whole if statement can be replaced by:
bin_message(n) = Difference(row, column) == 1; %no if
There's a bug in IA answer, the n = n + 1 shouldn't be inside the if.
Brian Tiffman
Brian Tiffman 2015년 11월 21일
Thank you so much! Its easier to do it without the loops, I dont know why were required to use them if we dont have to. We should be able to do it any way we want, as long as we get the correct answer. I really do appreciate your answer, it was easy to understand and follow along with. Could you check out my other question, http://www.mathworks.com/matlabcentral/answers/256134-hiding-a-message-in-an-image . I have the code mostly all done, but the reason I want you to check it out is because I have to have that correct in order for this part to be right. I think it looks pretty good, but just want a second opinion. Totally understand if you cant, I know youre probably really busy.

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

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2015년 11월 20일

댓글:

2015년 11월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by