How to change individual colors of an image

• To: mathgroup at smc.vnet.net
• Subject: [mg125015] How to change individual colors of an image
• From: Alexei Boulbitch <Alexei.Boulbitch at iee.lu>
• Date: Sat, 18 Feb 2012 06:22:30 -0500 (EST)
• Delivered-to: l-mathgroup@mail-archive0.wolfram.com

```Dear community,

My question relates to the work with an image. There are plenty of operators influencing the image as a whole. May be I have missed, but I could not find, if it is possible to work with all pixels possessing a given colour, (or may be, a group of colours close to one another) in  such  a way that this colour changes to another that is desired one.

To be precise, below I paste a full form of a small piece of an image with white (or light gray), black and red fragments. Is it possible to say, change black into blue? Light gray into yellow?

To see the image please copy-paste the 30 lists given below along with two code lines (combining them into the image) into Mathematica and execute:

lst1={{197,197,197},{197,197,197},{197,197,197},{196,196,196},{196,196,196},{188,188,188},{188,188,188},{188,188,188},{187,187,187},{187,187,187},{178,178,178},{178,178,178},{171,171,171},{171,171,171},{171,171,171},{165,165,165},{165,165,165},{125,125,125},{125,125,125},{125,125,125},{49,49,49},{49,49,49},{22,22,22},{22,22,22},{22,22,22},{26,26,26},{26,26,26},{34,34,34},{34,34,34},{34,34,34},{33,33,33},{33,33,33},{33,33,33},{33,33,33},{33,33,33}};

lst2={{197,197,197},{197,197,197},{197,197,197},{196,196,196},{196,196,196},{188,188,188},{188,188,188},{188,188,188},{187,187,187},{187,187,187},{178,178,178},{178,178,178},{171,171,171},{171,171,171},{171,171,171},{165,165,165},{165,165,165},{125,125,125},{125,125,125},{125,125,125},{49,49,49},{49,49,49},{22,22,22},{22,22,22},{22,22,22},{26,26,26},{26,26,26},{34,34,34},{34,34,34},{34,34,34},{33,33,33},{33,33,33},{33,33,33},{33,33,33},{33,33,33}};

lst3={{196,196,196},{196,196,196},{196,196,196},{187,187,187},{187,187,187},{187,187,187},{187,187,187},{187,187,187},{178,178,178},{178,178,178},{170,170,170},{170,170,170},{161,161,161},{161,161,161},{161,161,161},{156,156,156},{156,156,156},{139,139,139},{139,139,139},{139,139,139},{78,78,78},{78,78,78},{28,28,28},{28,28,28},{28,28,28},{31,31,31},{31,31,31},{33,33,33},{33,33,33},{33,33,33},{33,33,33},{33,33,33},{34,34,34},{34,34,34},{34,34,34}};

lst4={{196,196,196},{196,196,196},{196,196,196},{187,187,187},{187,187,187},{187,187,187},{187,187,187},{187,187,187},{178,178,178},{178,178,178},{170,170,170},{170,170,170},{161,161,161},{161,161,161},{161,161,161},{156,156,156},{156,156,156},{139,139,139},{139,139,139},{139,139,139},{78,78,78},{78,78,78},{28,28,28},{28,28,28},{28,28,28},{31,31,31},{31,31,31},{33,33,33},{33,33,33},{33,33,33},{33,33,33},{33,33,33},{34,34,34},{34,34,34},{34,34,34}};

lst5={{187,187,187},{187,187,187},{187,187,187},{187,187,187},{187,187,187},{180,180,180},{180,180,180},{180,180,180},{177,177,177},{177,177,177},{163,163,163},{163,163,163},{160,160,160},{160,160,160},{160,160,160},{148,148,148},{148,148,148},{143,143,143},{143,143,143},{143,143,143},{92,92,92},{92,92,92},{39,39,39},{39,39,39},{39,39,39},{30,30,30},{30,30,30},{29,29,29},{29,29,29},{29,29,29},{22,22,22},{22,22,22},{22,22,22},{22,22,22},{22,22,22}};

lst6={{187,187,187},{187,187,187},{187,187,187},{187,187,187},{187,187,187},{180,180,180},{180,180,180},{180,180,180},{177,177,177},{177,177,177},{163,163,163},{163,163,163},{160,160,160},{160,160,160},{160,160,160},{148,148,148},{148,148,148},{143,143,143},{143,143,143},{143,143,143},{92,92,92},{92,92,92},{39,39,39},{39,39,39},{39,39,39},{30,30,30},{30,30,30},{29,29,29},{29,29,29},{29,29,29},{22,22,22},{22,22,22},{22,22,22},{22,22,22},{22,22,22}};

lst7={{187,187,187},{187,187,187},{187,187,187},{187,187,187},{187,187,187},{180,180,180},{180,180,180},{180,180,180},{177,177,177},{177,177,177},{163,163,163},{163,163,163},{160,160,160},{160,160,160},{160,160,160},{148,148,148},{148,148,148},{143,143,143},{143,143,143},{143,143,143},{92,92,92},{92,92,92},{39,39,39},{39,39,39},{39,39,39},{30,30,30},{30,30,30},{29,29,29},{29,29,29},{29,29,29},{22,22,22},{22,22,22},{22,22,22},{22,22,22},{22,22,22}};

lst8={{188,188,188},{188,188,188},{188,188,188},{178,178,178},{178,178,178},{169,169,169},{169,169,169},{169,169,169},{164,164,164},{164,164,164},{163,163,163},{163,163,163},{153,153,153},{153,153,153},{153,153,153},{143,143,143},{143,143,143},{129,129,129},{129,129,129},{129,129,129},{94,94,94},{94,94,94},{40,40,40},{40,40,40},{40,40,40},{25,25,25},{25,25,25},{22,22,22},{22,22,22},{22,22,22},{24,24,24},{24,24,24},{24,24,24},{24,24,24},{24,24,24}};

lst9={{188,188,188},{188,188,188},{188,188,188},{178,178,178},{178,178,178},{169,169,169},{169,169,169},{169,169,169},{164,164,164},{164,164,164},{163,163,163},{163,163,163},{153,153,153},{153,153,153},{153,153,153},{143,143,143},{143,143,143},{129,129,129},{129,129,129},{129,129,129},{94,94,94},{94,94,94},{40,40,40},{40,40,40},{40,40,40},{25,25,25},{25,25,25},{22,22,22},{22,22,22},{22,22,22},{24,24,24},{24,24,24},{24,24,24},{24,24,24},{24,24,24}};

lst10={{188,188,188},{188,188,188},{188,188,188},{178,178,178},{178,178,178},{169,169,169},{169,169,169},{169,169,169},{164,164,164},{164,164,164},{163,163,163},{163,163,163},{153,153,153},{153,153,153},{153,153,153},{143,143,143},{143,143,143},{129,129,129},{129,129,129},{129,129,129},{94,94,94},{94,94,94},{40,40,40},{40,40,40},{40,40,40},{25,25,25},{25,25,25},{22,22,22},{22,22,22},{22,22,22},{24,24,24},{24,24,24},{24,24,24},{24,24,24},{24,24,24}};

lst11={{180,180,180},{180,180,180},{180,180,180},{177,177,177},{177,177,177},{162,162,162},{162,162,162},{162,162,162},{163,163,163},{163,163,163},{153,153,153},{153,153,153},{145,145,145},{145,145,145},{145,145,145},{138,138,138},{138,138,138},{127,127,127},{127,127,127},{127,127,127},{89,89,89},{89,89,89},{37,37,37},{37,37,37},{37,37,37},{20,19,19},{20,19,19},{19,24,24},{19,24,24},{19,24,24},{17,24,24},{17,24,24},{23,20,20},{23,20,20},{23,20,20}};

lst12={{180,180,180},{180,180,180},{180,180,180},{177,177,177},{177,177,177},{162,162,162},{162,162,162},{162,162,162},{163,163,163},{163,163,163},{153,153,153},{153,153,153},{145,145,145},{145,145,145},{145,145,145},{138,138,138},{138,138,138},{127,127,127},{127,127,127},{127,127,127},{89,89,89},{89,89,89},{37,37,37},{37,37,37},{37,37,37},{20,19,19},{20,19,19},{19,24,24},{19,24,24},{19,24,24},{17,24,24},{17,24,24},{23,20,20},{23,20,20},{23,20,20}};

lst13={{180,180,180},{180,180,180},{180,180,180},{177,177,177},{177,177,177},{162,162,162},{162,162,162},{162,162,162},{163,163,163},{163,163,163},{153,153,153},{153,153,153},{145,145,145},{145,145,145},{145,145,145},{138,138,138},{138,138,138},{127,127,127},{127,127,127},{127,127,127},{89,89,89},{89,89,89},{37,37,37},{37,37,37},{37,37,37},{20,19,19},{20,19,19},{19,24,24},{19,24,24},{19,24,24},{17,24,24},{17,24,24},{23,20,20},{23,20,20},{23,20,20}};

lst14={{180,180,180},{180,180,180},{180,180,180},{177,177,177},{177,177,177},{162,162,162},{162,162,162},{162,162,162},{163,163,163},{163,163,163},{153,153,153},{153,153,153},{145,145,145},{145,145,145},{145,145,145},{138,138,138},{138,138,138},{127,127,127},{127,127,127},{127,127,127},{89,89,89},{89,89,89},{37,37,37},{37,37,37},{37,37,37},{20,19,19},{20,19,19},{19,24,24},{19,24,24},{19,24,24},{17,24,24},{17,24,24},{23,20,20},{23,20,20},{23,20,20}};

lst15={{180,180,180},{180,180,180},{180,180,180},{170,170,170},{170,170,170},{161,161,161},{161,161,161},{161,161,161},{155,155,155},{155,155,155},{152,152,152},{152,152,152},{136,136,136},{136,136,136},{136,136,136},{127,127,127},{127,127,127},{112,112,112},{112,112,112},{112,112,112},{82,81,81},{82,81,81},{30,32,32},{30,32,32},{30,32,32},{6,20,20},{6,20,20},{10,24,24},{10,24,24},{10,24,24},{32,20,20},{32,20,20},{66,16,16},{66,16,16},{66,16,16}};

lst16={{180,180,180},{180,180,180},{180,180,180},{170,170,170},{170,170,170},{161,161,161},{161,161,161},{161,161,161},{155,155,155},{155,155,155},{152,152,152},{152,152,152},{136,136,136},{136,136,136},{136,136,136},{127,127,127},{127,127,127},{112,112,112},{112,112,112},{112,112,112},{82,81,81},{82,81,81},{30,32,32},{30,32,32},{30,32,32},{6,20,20},{6,20,20},{10,24,24},{10,24,24},{10,24,24},{32,20,20},{32,20,20},{66,16,16},{66,16,16},{66,16,16}};

lst17={{180,180,180},{180,180,180},{180,180,180},{170,170,170},{170,170,170},{161,161,161},{161,161,161},{161,161,161},{155,155,155},{155,155,155},{152,152,152},{152,152,152},{136,136,136},{136,136,136},{136,136,136},{127,127,127},{127,127,127},{112,112,112},{112,112,112},{112,112,112},{82,81,81},{82,81,81},{30,32,32},{30,32,32},{30,32,32},{6,20,20},{6,20,20},{10,24,24},{10,24,24},{10,24,24},{32,20,20},{32,20,20},{66,16,16},{66,16,16},{66,16,16}};

lst18={{162,162,162},{162,162,162},{162,162,162},{163,163,163},{163,163,163},{155,155,155},{155,155,155},{155,155,155},{152,152,152},{152,152,152},{138,138,138},{138,138,138},{135,135,135},{135,135,135},{135,135,135},{120,120,120},{120,120,120},{107,106,106},{107,106,106},{107,106,106},{65,68,68},{65,68,68},{24,30,30},{24,30,30},{24,30,30},{13,16,16},{13,16,16},{27,18,18},{27,18,18},{27,18,18},{57,6,6},{57,6,6},{98,4,4},{98,4,4},{98,4,4}};

lst19={{162,162,162},{162,162,162},{162,162,162},{163,163,163},{163,163,163},{155,155,155},{155,155,155},{155,155,155},{152,152,152},{152,152,152},{138,138,138},{138,138,138},{135,135,135},{135,135,135},{135,135,135},{120,120,120},{120,120,120},{107,106,106},{107,106,106},{107,106,106},{65,68,68},{65,68,68},{24,30,30},{24,30,30},{24,30,30},{13,16,16},{13,16,16},{27,18,18},{27,18,18},{27,18,18},{57,6,6},{57,6,6},{98,4,4},{98,4,4},{98,4,4}};

lst20={{162,162,162},{162,162,162},{162,162,162},{163,163,163},{163,163,163},{155,155,155},{155,155,155},{155,155,155},{152,152,152},{152,152,152},{138,138,138},{138,138,138},{135,135,135},{135,135,135},{135,135,135},{120,120,120},{120,120,120},{107,106,106},{107,106,106},{107,106,106},{65,68,68},{65,68,68},{24,30,30},{24,30,30},{24,30,30},{13,16,16},{13,16,16},{27,18,18},{27,18,18},{27,18,18},{57,6,6},{57,6,6},{98,4,4},{98,4,4},{98,4,4}};

lst21={{168,168,168},{168,168,168},{168,168,168},{155,155,155},{155,155,155},{163,163,163},{163,163,163},{163,163,163},{144,144,144},{144,144,144},{134,134,134},{134,134,134},{122,122,122},{122,122,122},{122,122,122},{118,118,118},{118,118,118},{87,92,92},{87,92,92},{87,92,92},{48,53,53},{48,53,53},{28,14,14},{28,14,14},{28,14,14},{47,11,11},{47,11,11},{83,7,7},{83,7,7},{83,7,7},{121,3,3},{121,3,3},{142,3,3},{142,3,3},{142,3,3}};

lst22={{154,154,154},{154,154,154},{154,154,154},{152,152,152},{152,152,152},{138,138,138},{138,138,138},{138,138,138},{136,136,136},{136,136,136},{119,122,122},{119,122,122},{110,118,118},{110,118,118},{110,118,118},{92,92,92},{92,92,92},{73,55,55},{73,55,55},{73,55,55},{64,11,11},{64,11,11},{77,2,2},{77,2,2},{77,2,2},{104,0,0},{104,0,0},{129,0,0},{129,0,0},{129,0,0},{141,0,0},{141,0,0},{145,0,0},{145,0,0},{145,0,0}};

lst23={{154,154,154},{154,154,154},{154,154,154},{152,152,152},{152,152,152},{138,138,138},{138,138,138},{138,138,138},{136,136,136},{136,136,136},{119,122,122},{119,122,122},{110,118,118},{110,118,118},{110,118,118},{92,92,92},{92,92,92},{73,55,55},{73,55,55},{73,55,55},{64,11,11},{64,11,11},{77,2,2},{77,2,2},{77,2,2},{104,0,0},{104,0,0},{129,0,0},{129,0,0},{129,0,0},{141,0,0},{141,0,0},{145,0,0},{145,0,0},{145,0,0}};

lst24={{154,154,154},{154,154,154},{154,154,154},{152,152,152},{152,152,152},{138,138,138},{138,138,138},{138,138,138},{136,136,136},{136,136,136},{119,122,122},{119,122,122},{110,118,118},{110,118,118},{110,118,118},{92,92,92},{92,92,92},{73,55,55},{73,55,55},{73,55,55},{64,11,11},{64,11,11},{77,2,2},{77,2,2},{77,2,2},{104,0,0},{104,0,0},{129,0,0},{129,0,0},{129,0,0},{141,0,0},{141,0,0},{145,0,0},{145,0,0},{145,0,0}};

lst25={{164,164,164},{164,164,164},{164,164,164},{144,144,144},{144,144,144},{134,134,134},{134,134,134},{134,134,134},{122,121,121},{122,121,121},{119,122,122},{119,122,122},{88,96,96},{88,96,96},{88,96,96},{67,48,48},{67,48,48},{81,12,12},{81,12,12},{81,12,12},{104,2,2},{104,2,2},{110,0,0},{110,0,0},{110,0,0},{117,0,0},{117,0,0},{132,0,0},{132,0,0},{132,0,0},{137,0,0},{137,0,0},{134,0,0},{134,0,0},{134,0,0}};

lst26={{164,164,164},{164,164,164},{164,164,164},{144,144,144},{144,144,144},{134,134,134},{134,134,134},{134,134,134},{122,121,121},{122,121,121},{119,122,122},{119,122,122},{88,96,96},{88,96,96},{88,96,96},{67,48,48},{67,48,48},{81,12,12},{81,12,12},{81,12,12},{104,2,2},{104,2,2},{110,0,0},{110,0,0},{110,0,0},{117,0,0},{117,0,0},{132,0,0},{132,0,0},{132,0,0},{137,0,0},{137,0,0},{134,0,0},{134,0,0},{134,0,0}};

lst27={{164,164,164},{164,164,164},{164,164,164},{144,144,144},{144,144,144},{134,134,134},{134,134,134},{134,134,134},{122,121,121},{122,121,121},{119,122,122},{119,122,122},{88,96,96},{88,96,96},{88,96,96},{67,48,48},{67,48,48},{81,12,12},{81,12,12},{81,12,12},{104,2,2},{104,2,2},{110,0,0},{110,0,0},{110,0,0},{117,0,0},{117,0,0},{132,0,0},{132,0,0},{132,0,0},{137,0,0},{137,0,0},{134,0,0},{134,0,0},{134,0,0}};

lst28={{138,138,138},{138,138,138},{138,138,138},{137,137,137},{137,137,137},{120,120,120},{120,120,120},{120,120,120},{108,108,108},{108,108,108},{70,70,70},{70,70,70},{31,35,35},{31,35,35},{31,35,35},{15,5,5},{15,5,5},{50,0,0},{50,0,0},{50,0,0},{77,0,0},{77,0,0},{95,0,0},{95,0,0},{95,0,0},{106,0,0},{106,0,0},{116,0,0},{116,0,0},{116,0,0},{118,0,0},{118,0,0},{122,0,0},{122,0,0},{122,0,0}};

lst29={{138,138,138},{138,138,138},{138,138,138},{137,137,137},{137,137,137},{120,120,120},{120,120,120},{120,120,120},{108,108,108},{108,108,108},{70,70,70},{70,70,70},{31,35,35},{31,35,35},{31,35,35},{15,5,5},{15,5,5},{50,0,0},{50,0,0},{50,0,0},{77,0,0},{77,0,0},{95,0,0},{95,0,0},{95,0,0},{106,0,0},{106,0,0},{116,0,0},{116,0,0},{116,0,0},{118,0,0},{118,0,0},{122,0,0},{122,0,0},{122,0,0}};

lst30={{138,138,138},{138,138,138},{138,138,138},{137,137,137},{137,137,137},{120,120,120},{120,120,120},{120,120,120},{108,108,108},{108,108,108},{70,70,70},{70,70,70},{31,35,35},{31,35,35},{31,35,35},{15,5,5},{15,5,5},{50,0,0},{50,0,0},{50,0,0},{77,0,0},{77,0,0},{95,0,0},{95,0,0},{95,0,0},{106,0,0},{106,0,0},{116,0,0},{116,0,0},{116,0,0},{118,0,0},{118,0,0},{122,0,0},{122,0,0},{122,0,0}};

lstTotal=Table[ToExpression["lst"<>ToString[i]],{i,1,30}];

Image[RawArray["Byte",lstTotal],"Byte",ColorSpace->"RGB",Interleaving->True]

Thank you, Alexei

Alexei BOULBITCH, Dr., habil.

IEE S.A.

ZAE Weiergewan,

11, rue Edmond Reuter,

L-5326 Contern, LUXEMBOURG

Office phone :  +352-2454-2566

Office fax:       +352-2454-3566

mobile phone:  +49 151 52 40 66 44

e-mail: alexei.boulbitch at iee.lu<mailto:alexei.boulbitch at iee.lu>

```

• Prev by Date: How best to implement a hash table in Mathematica
• Next by Date: Re: Extensive replacement of trigonometric functions
• Previous by thread: Re: How best to implement a hash table in Mathematica
• Next by thread: Re: How to change individual colors of an image