Extracting a message from a picture?
古いコメントを表示
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)
採用された回答
その他の回答 (1 件)
Image Analyst
2015 年 11 月 20 日
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 件のコメント
Brian Tiffman
2015 年 11 月 20 日
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
2015 年 11 月 21 日
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.
Guillaume
2015 年 11 月 21 日
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
2015 年 11 月 21 日
カテゴリ
ヘルプ センター および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!