6
$\begingroup$

My data is as shown below. I want to make an image where the 1's have one colour, the 2's have another colour and 0's are rendered as blank. How can I achieve that?

0000000000000000000000000000000000000000
0000000000000000000000000000000000000000
0000000000000000000000000000000000000000
0000000000000000000000000000000000000000
0000000000000000000000000000000000000000
0000000000000000000100100100000000000000
0000000000000000001211211210000000000000
0000000000000000001221212210000000000000
0000000000000000012221222211000000000000
0000000000000000122222222222111000000000
0000000000000110122122222222122100000000
0000000000011221212222222222122100000000
0000000000122212222222222221222100000000
0000000100122222212222222222222111100000
0000001211222212222222222221222122210000
0000001222222222222222222222211221100000
0000000122222222222222222222122221000000
0000000011122222222222222222222221000000
0000000001122222222222222221222221000000
0000000012222222222222222222222222111100
0000000001222222222222222222221222222210
0000000012222222222222222222222222222210
0000000012222222222222222222222222222221
0000000122222222222222222222222222222210
0000001122222222222222222222222222222100
0000012222222222222222222222222222222210
0000012222122222222222222222222222121210
0000001121122222222222221222222212212210
0000000121011112222222222222221222212100
0000000010000122222222222122211222101000
0000000000000122222222221121101211000000
0000000000001222122121221221000100000000
0000000000012212221122211110000000000000
0000000000001222121011212100000000000000
0000000000012211222101222210000000000000
0000000000012210121001212210000000000000
0000000000012100010000101100000000000000
0000000000001000000000000000000000000000
0000000000000000000000000000000000000000
0000000000000000000000000000000000000000
$\endgroup$

3 Answers 3

9
$\begingroup$

This is equivalent to the data in the OP:

data = Uncompress["1:eJzdlLsVwyAMRV1lj2zAZZSkTZUFsnCGCQjMR3zdRvaxC18/noTQ/f15PL+34zCb8TLYP2A57zWLJdxbrHWg3WEd5Un3YMUKFoMCb1j3jahqgzwDltPpmk1GC7TLkpxWuLeMYqWgXd1Tu2S7IRlo3T4clmpzg5F2pw4ty4gdqKZS1LpDxyK+p3uVtaxq1tcdFSyhmV2oVrptL5Scv2oPygb5jaqD/5V2n+OCai/QvqUbQ0vSnIuaFVfS153eMekUkUwW00efzXJhmM8SYiKEMs1YcjJxs+asFM+s5xk5G+9j6kGP3Ck7iyvsD3y6V+M="];

From there:

ArrayPlot[(FromDigits /@ Characters[#]) & /@ StringSplit[data, "\n"], 
          ColorRules -> {1 -> Red, 2 -> Blue, _ -> White}]
$\endgroup$
9
$\begingroup$

Stealing data from J.M.:

Colorize[ToCharacterCode[StringSplit[data]] - 48]

enter image description here

$\endgroup$
5
$\begingroup$

Also stealing from J.M....

s = Uncompress["1:eJzdlLsVwyAMRV1lj2zAZZSkTZUFsnCGCQjMR3zdRvaxC18/noTQ/f15PL+34zCb8TLYP2A57zWLJdxbrHWg3WEd5Un3YMUKFoMCb1j3jahqgzwDltPpmk1GC7TLkpxWuLeMYqWgXd1Tu2S7IRlo3T4clmpzg5F2pw4ty4gdqKZS1LpDxyK+p3uVtaxq1tcdFSyhmV2oVrptL5Scv2oPygb5jaqD/5V2n+OCai/QvqUbQ0vSnIuaFVfS153eMekUkUwW00efzXJhmM8SYiKEMs1YcjJxs+asFM+s5xk5G+9j6kGP3Ck7iyvsD3y6V+M="];
ClearAll[f];
f["0"] = List @@ ColorData[97][1];
f["1"] = List @@ ColorData[97][2];
f["2"] = List @@ ColorData[97][3];
img = Image[Map[f, Characters /@ StringSplit[s], {2}]]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.