0
$\begingroup$

I have a 200x200 grayscale map map = Image[data, "Byte"] together with a matrix plot path = MatrixPlot[{{0,0,...,0,a,...0},{0,0,...,b,b,b...},...,{a,b,b,...}},ColorRules -> {a -> Black, b -> Green}] that resembles a route in the map.

enter image description here enter image description here

How can I join both together so that the green route is shown in the map? I tried Show[map,path] but it don't work.

$\endgroup$
1
  • 2
    $\begingroup$ It sounds like you want ImageCompose[], but you'll need to make an Image[] object directly from your matrix without using MatrixPlot[]. $\endgroup$ Commented Mar 15, 2019 at 6:25

1 Answer 1

2
$\begingroup$

Here is a possible solution. I don't have your matrix describing the route, so I used this random-ish one for the purpose of demonstration:

path={{1,0},{3,1},{5,2},{5,3},{5,4},{8,5},{9,6},{10,7},{11,8},{12,9},{12,10},{13,11},{15,12},{17,13},{18,14},{18,15},{19,16},{19,17},{20,18},{22,19},{24,20},{24,21},{24,22},{25,23},{25,24},{25,25},{26,26},{27,27},{27,28},{28,29},{29,30},{30,31},{31,32},{31,33},{34,34},{36,35},{36,36},{36,37},{38,38},{39,39},{39,40},{40,41},{42,42},{43,43},{45,44},{46,45},{46,46},{48,47},{49,48},{49,49},{53,50},{54,51},{57,52},{58,53},{60,54},{62,55},{62,56},{63,57},{64,58},{64,59},{65,60},{66,61},{66,62},{67,63},{68,64},{72,65},{73,66},{77,67},{77,68},{78,69},{78,70},{79,71},{80,72},{81,73},{84,74},{84,75},{86,76},{88,77},{92,78},{92,79},{93,80},{95,81},{95,82},{96,83},{97,84},{97,85},{98,86},{100,87},{100,88},{102,89},{102,90},{103,91},{103,92},{104,93},{106,94},{106,95},{106,96},{107,97},{107,98},{107,99},{107,100},{108,101},{108,102},{108,103},{108,104},{109,105},{113,106},{115,107},{115,108},{117,109},{119,110},{119,111},{120,112},{120,113},{121,114},{121,115},{123,116},{124,117},{124,118},{124,119},{124,120},{125,121},{127,122},{128,123},{129,124},{130,125},{132,126},{133,127},{133,128},{134,129},{134,130},{136,131},{137,132},{137,133},{137,134},{139,135},{139,136},{142,137},{142,138},{143,139},{143,140},{146,141},{146,142},{146,143},{146,144},{147,145},{148,146},{149,147},{150,148},{151,149},{152,150},{153,151},{154,152},{156,153},{156,154},{157,155},{161,156},{161,157},{167,158},{168,159},{169,160},{170,161},{170,162},{171,163},{171,164},{172,165},{172,166},{173,167},{174,168},{174,169},{174,170},{175,171},{175,172},{175,173},{177,174},{177,175},{178,176},{180,177},{182,178},{186,179},{187,180},{188,181},{188,182},{188,183},{189,184},{190,184}};

t = Normal[SparseArray[path + 1 -> 1, {200, 200}]];

MatrixPlot[t, ColorRules -> {1 -> Green}]

matrixplot

Turn the matrix into an image: i1 = Image[t]

i1

You might want a thicker line: i2 = ImageConvolve[Image[t, "bit"], DiskMatrix[1]]

i2

Change the image to RGB and make the line green: i3 = Image[Map[{#, 1, #} &, ImageData[ColorNegate[i2]], {2}]]

i3

Overlay the path onto the map:ImageCompose[map, SetAlphaChannel[i3, i2]] The alpha channel makes the background of the route image transparent.

overlay

$\endgroup$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.