Skip to main content
edited body
Source Link
Putterboy
  • 4.7k
  • 1
  • 21
  • 31

I tried to use ColorReplace to change the colors obtained from MorphologicalComponents. However some of the changes didn't follow the rules specified, Is there any reasons?

im2 = Binarize@Import["https://i.sstatic.net/ZDeYq.jpg"];
im3 = Colorize@ MorphologicalComponents@im2 
colors = DominantColors[im3, 5] 

enter image description here

Now trying to change the colors accordingly,

ColorReplace[im3, {
  colors[[2]] -> Red, 
  colors[[3]] -> Blue, 
  colors[[4]] -> Green, 
  colors[[5]] -> Yellow
  }]

TwoOne of the changes did not follow the rules specified:

enter image description here

I tried to use ColorReplace to change the colors obtained from MorphologicalComponents. However some of the changes didn't follow the rules specified, Is there any reasons?

im2 = Binarize@Import["https://i.sstatic.net/ZDeYq.jpg"];
im3 = Colorize@ MorphologicalComponents@im2 
colors = DominantColors[im3, 5] 

enter image description here

Now trying to change the colors accordingly,

ColorReplace[im3, {
  colors[[2]] -> Red, 
  colors[[3]] -> Blue, 
  colors[[4]] -> Green, 
  colors[[5]] -> Yellow
  }]

Two of the changes did not follow the rules specified:

enter image description here

I tried to use ColorReplace to change the colors obtained from MorphologicalComponents. However some of the changes didn't follow the rules specified, Is there any reasons?

im2 = Binarize@Import["https://i.sstatic.net/ZDeYq.jpg"];
im3 = Colorize@ MorphologicalComponents@im2 
colors = DominantColors[im3, 5] 

enter image description here

Now trying to change the colors accordingly,

ColorReplace[im3, {
  colors[[2]] -> Red, 
  colors[[3]] -> Blue, 
  colors[[4]] -> Green, 
  colors[[5]] -> Yellow
  }]

One of the changes did not follow the rules specified:

enter image description here

Source Link
Putterboy
  • 4.7k
  • 1
  • 21
  • 31

Why ColorReplace does not follow the rules specified?

I tried to use ColorReplace to change the colors obtained from MorphologicalComponents. However some of the changes didn't follow the rules specified, Is there any reasons?

im2 = Binarize@Import["https://i.sstatic.net/ZDeYq.jpg"];
im3 = Colorize@ MorphologicalComponents@im2 
colors = DominantColors[im3, 5] 

enter image description here

Now trying to change the colors accordingly,

ColorReplace[im3, {
  colors[[2]] -> Red, 
  colors[[3]] -> Blue, 
  colors[[4]] -> Green, 
  colors[[5]] -> Yellow
  }]

Two of the changes did not follow the rules specified:

enter image description here