Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #8598 > unrolled thread
| Started by | Alexei Boulbitch <Alexei.Boulbitch@iee.lu> |
|---|---|
| First post | 2012-02-18 11:26 +0000 |
| Last post | 2012-02-20 07:59 +0000 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
How to change individual colors of an image Alexei Boulbitch <Alexei.Boulbitch@iee.lu> - 2012-02-18 11:26 +0000
Re: How to change individual colors of an image Szabolcs Horvát <szhorvat@gmail.com> - 2012-02-20 07:59 +0000
| From | Alexei Boulbitch <Alexei.Boulbitch@iee.lu> |
|---|---|
| Date | 2012-02-18 11:26 +0000 |
| Subject | How to change individual colors of an image |
| Message-ID | <jho1tn$5r0$1@smc.vnet.net> |
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@iee.lu<mailto:alexei.boulbitch@iee.lu>
[toc] | [next] | [standalone]
| From | Szabolcs Horvát <szhorvat@gmail.com> |
|---|---|
| Date | 2012-02-20 07:59 +0000 |
| Message-ID | <jhsug5$nrc$1@smc.vnet.net> |
| In reply to | #8598 |
On 2/18/2012 1:26 PM, Alexei Boulbitch wrote:
> 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:
>
>
>
Dear Alexei,
A simple way to send complex expressions is using Compress/Uncompress
(see at the end of this message).
There are several ways to achieve what you need, but I am going to show
a more general way here, called masking. This can be generalized to
many problems.
Suppose the image is stored in variable img
Let's first find all pixels that have colour {138, 138, 138}/255
mask = Binarize[img, # == {138, 138, 138}/255 &]
Alternatively use colours that are close to this shade of grey:
mask = Binarize[img, Norm[# - {138, 138, 138}/255] < 0.05 &]
Then change the image in the matching region green (i.e. colour {0,1,0}:
ImageApply[{0, 1, 0} &, img, Masking -> mask]
If you have Mathematica 7, you could use ImageApply directly:
ImageApply[If[# == {138, 138, 138}/255, {0, 1, 0}, #] &, img]
------------------->8------------------
This is the image in a more compact and ASCII-only format:
img = Uncompress@
"1:eJzt189r03AYx/GQ/pisddY1zKgz61Zk3qzCGN5cN5QdJjQVVCi6VLLNWt
uRtdlSEBnIdIo/Bh7UeVA3wR8nxds8zv/LJ8/DJ7S5CjuEvXg3JDR8H8q3tG
S02jQX4oqirCToMPvAWrQXVP/yCB1Ma3XKcSyv7N9Q9Fp2NUYnBr3y9PLP/8
I++wN77Bf7AV/YQ7jAhuAUG4PRXgc2aB/2esmI7+wTfGDP4RobhhEWWj+Ye2
CDQuv/hp9sh32EN+wVVNg4GOwMDPWK3qDgayab8g12mQx6B7L+Otxm5+AkC1
bWe0VvUGhTPkP3iC14xh7BLXYWtGyWyuq6dJw7oWnS4aD/HxT6tdlmb9lTkP
WXwSyVKCOXk5KaRvXrupTTNKqYyUjRGxTalG2QEbIpT2CN3a/VpKmZGUo3DO
loJkOdHhyULiWTVDUel6I36CvI+jvwmm2wDrjsRqUiFSYmqOGBAel8KkWV+/
okLxajXqL30P0RiOz+aqdDNVxXkv+F2clJ6XIqRc2pqrSkKNQ6esFtoegN2o
XuTfH3xfMoGXRzfl6aLhSoUjotLdHiqtpQFKnNPUab3AaK3qBgUzbZGtTZFT
aSz0vHEgnqoqJIc9wdVONayOU6KHqDgucMeQTxr8x23V7pp5PpZr3plJetu3
bZf/AwrxZDN6X955dGy3bqtuXeayzyO9edtv0P0u64wA=="
-------------------8<------------------
This is how it was generated:
wrap[string_, width_] :=
StringJoin@
Riffle[Partition[Characters[string], width, width, {1, 1}, {}],
"\n"]
wrap[Compress[img], 60]
--
Szabolcs Horvát
Visit Mathematica.SE: http://mathematica.stackexchange.com/
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web