Loren on the Art of MATLAB

Turn ideas into MATLAB

What was Sheraton Trying to Tell Us? 6

Posted by Loren Shure,

What was Sheraton Trying to Tell Us?

Today's post is by Sean de Wolski and me. We spent a few days this week at training for the start of the year, held in a Sheraton hotel.

At the completion of our stay, we each got a note in our rooms. Here is a sample.

Actually we read this in with the App from the Image Acquisition Toolbox and cropped the image (imcrop from Image Processing Toolbox) to just display the mysterious binary text.

Using functionality from the Computer Vision System Toolbox, we then converted our binary text using the ocr (Optical Character Recognition) function.

Icrop = imread('Sher.png');
bintext = ocr(Icrop)
str = bintext.Words;
str = [str{:}];
bintext = 
  ocrText with properties:

                      Text: '010101000110100001100001011011100110101100100...'
    CharacterBoundingBoxes: [879x4 double]
      CharacterConfidences: [879x1 single]
                     Words: {14x1 cell}
         WordBoundingBoxes: [14x4 double]
           WordConfidences: [14x1 single]

Next guess was how the text was encoded - 4 bits, 8 bits? We figured 8 was most likely.

newstr = reshape(str',8,[])';

Let's look at the first few lines.

snip = newstr(1:3,:)
snip =
01010100
01101000
01100001

Could these be text?

bin2dec(snip)
ans =
    84
   104
    97

These could be ASCII characters!

Have you ever misread an O for a 0? Or an l for a 1? We have! So we decided to program defensively for those and any other weird swaps that might confuse the OCR.

newstr(newstr == 'O') = '0';
newstr(newstr ~='0') = '1';

Finally let's write out the result.

message = char(bin2dec(newstr))';

disp(message(1:74))
disp(message(75:end))
Thank you for your continued loyalty to Sheraton Boston. It is a pleasure 
to host Mathworks year after year.


Get the MATLAB code

Published with MATLAB® R2014b

3 views (last 30 days)  | |

Comments

To leave a comment, please click here to sign in to your MathWorks Account or create a new one.