Loren on the Art of MATLAB

Turn ideas into MATLAB


Loren on the Art of MATLAB has been archived and will not be updated.

What was Sheraton Trying to Tell Us?

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 =

Could these be text?

ans =

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))';

Thank you for your continued loyalty to Sheraton Boston. It is a pleasure 
to host Mathworks year after year.

Published with MATLAB® R2014b

  • print


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