Coloring a map of India
Clash Royale CLAN TAG#URR8PPP
up vote
4
down vote
favorite
Below is a map of India (img
).
and I can visualize it in the following way:
imgbin = Binarize@img;
MorphologicalComponents[imgbin] // Colorize
and the result is:
Edit
Following a manual approach, I can isolate the small components:
sc = SelectComponents[imgbin, #Count < 60 &];
However, this gives me
Now I find the coordinates of the centroids:
centroids = ComponentMeasurements[sc, "Centroid"];
This gives me
1 -> 523.425, 182.274, 2 -> 545.125, 182.563, 3 -> 521.089, 154.518,
4 -> 96.2778, 154.722, 5 -> 101.5, 150.625, 6 -> 285.375, 146.667,
7 -> 111.7, 136., 8 -> 517.868, 133.947, 9 -> 91.8846, 134.885,
10 -> 99.3889, 135.167, 11 -> 95.0882, 122.382, 12 -> 531.136, 105.409,
13 -> 535.5, 94., 14 -> 541.4, 92.6, 15 -> 551.833, 93.8333,
16 -> 540.333, 86.5833, 17 -> 564., 63.5, 18 -> 557.929, 61.5,
19 -> 558.833, 55.8333, 20 -> 567.5, 27., 21 -> 575.689, 20.3491
From this information, I think, the grouping can be done. I need to choose two thresholds for the X
coordinates of the centroids. Manually, I can set the thresholds as 100
and 200
. Then, the components having centroids with x < 100
will be grouped into one, the component having the centroid with 100 < x < 200
will be grouped into another one (this component should be discarded as it is already considered as a component earlier) and finally the components having centroids with x > 200
will be grouped into the second one.
However, I wish to group some of the components as shown below:
That is, the components inside the circle at the bottom left should be grouped into a single component and visualized with a single color and the components inside the ellipse at the bottom right should be grouped into another single component and visualized with another unique color while keeping the rest of the map unchanged.
How can I do so?
Edit 2: I can now group the components desired in a very manual way as follows:
scleft = SelectComponents[
imgbin, #Count < 80 && #Centroid[[1]] < 130 &];
scright =
SelectComponents[imgbin, #Count < 80 && #Centroid[[1]] > 350 &];
and the components for the rest of the parts
mc = MorphologicalComponents[
ImageSubtract[imgbin, ImageAdd[scleft, scright]]];
Now how can I join these components - scleft
, scright
and mc
and get the desired result?
image-processing visualization geography
 |Â
show 1 more comment
up vote
4
down vote
favorite
Below is a map of India (img
).
and I can visualize it in the following way:
imgbin = Binarize@img;
MorphologicalComponents[imgbin] // Colorize
and the result is:
Edit
Following a manual approach, I can isolate the small components:
sc = SelectComponents[imgbin, #Count < 60 &];
However, this gives me
Now I find the coordinates of the centroids:
centroids = ComponentMeasurements[sc, "Centroid"];
This gives me
1 -> 523.425, 182.274, 2 -> 545.125, 182.563, 3 -> 521.089, 154.518,
4 -> 96.2778, 154.722, 5 -> 101.5, 150.625, 6 -> 285.375, 146.667,
7 -> 111.7, 136., 8 -> 517.868, 133.947, 9 -> 91.8846, 134.885,
10 -> 99.3889, 135.167, 11 -> 95.0882, 122.382, 12 -> 531.136, 105.409,
13 -> 535.5, 94., 14 -> 541.4, 92.6, 15 -> 551.833, 93.8333,
16 -> 540.333, 86.5833, 17 -> 564., 63.5, 18 -> 557.929, 61.5,
19 -> 558.833, 55.8333, 20 -> 567.5, 27., 21 -> 575.689, 20.3491
From this information, I think, the grouping can be done. I need to choose two thresholds for the X
coordinates of the centroids. Manually, I can set the thresholds as 100
and 200
. Then, the components having centroids with x < 100
will be grouped into one, the component having the centroid with 100 < x < 200
will be grouped into another one (this component should be discarded as it is already considered as a component earlier) and finally the components having centroids with x > 200
will be grouped into the second one.
However, I wish to group some of the components as shown below:
That is, the components inside the circle at the bottom left should be grouped into a single component and visualized with a single color and the components inside the ellipse at the bottom right should be grouped into another single component and visualized with another unique color while keeping the rest of the map unchanged.
How can I do so?
Edit 2: I can now group the components desired in a very manual way as follows:
scleft = SelectComponents[
imgbin, #Count < 80 && #Centroid[[1]] < 130 &];
scright =
SelectComponents[imgbin, #Count < 80 && #Centroid[[1]] > 350 &];
and the components for the rest of the parts
mc = MorphologicalComponents[
ImageSubtract[imgbin, ImageAdd[scleft, scright]]];
Now how can I join these components - scleft
, scright
and mc
and get the desired result?
image-processing visualization geography
What have you tried so far ? Understand your original attempts will help us get started in helping you.
â user6014
3 hours ago
@user6014 I am not sure. Maybe group them by the components' centroid coordinates.
â Majis
3 hours ago
If you post code examples of your best attempt so far it will be a good starting point for someone to build off of and hopefully get you to the next step.
â user6014
3 hours ago
@user6014 see my edit.
â Majis
3 hours ago
1
Majis, may i suggest you re-visit your previous questions and check if any of the answers is worth accepting?
â kglr
1 hour ago
 |Â
show 1 more comment
up vote
4
down vote
favorite
up vote
4
down vote
favorite
Below is a map of India (img
).
and I can visualize it in the following way:
imgbin = Binarize@img;
MorphologicalComponents[imgbin] // Colorize
and the result is:
Edit
Following a manual approach, I can isolate the small components:
sc = SelectComponents[imgbin, #Count < 60 &];
However, this gives me
Now I find the coordinates of the centroids:
centroids = ComponentMeasurements[sc, "Centroid"];
This gives me
1 -> 523.425, 182.274, 2 -> 545.125, 182.563, 3 -> 521.089, 154.518,
4 -> 96.2778, 154.722, 5 -> 101.5, 150.625, 6 -> 285.375, 146.667,
7 -> 111.7, 136., 8 -> 517.868, 133.947, 9 -> 91.8846, 134.885,
10 -> 99.3889, 135.167, 11 -> 95.0882, 122.382, 12 -> 531.136, 105.409,
13 -> 535.5, 94., 14 -> 541.4, 92.6, 15 -> 551.833, 93.8333,
16 -> 540.333, 86.5833, 17 -> 564., 63.5, 18 -> 557.929, 61.5,
19 -> 558.833, 55.8333, 20 -> 567.5, 27., 21 -> 575.689, 20.3491
From this information, I think, the grouping can be done. I need to choose two thresholds for the X
coordinates of the centroids. Manually, I can set the thresholds as 100
and 200
. Then, the components having centroids with x < 100
will be grouped into one, the component having the centroid with 100 < x < 200
will be grouped into another one (this component should be discarded as it is already considered as a component earlier) and finally the components having centroids with x > 200
will be grouped into the second one.
However, I wish to group some of the components as shown below:
That is, the components inside the circle at the bottom left should be grouped into a single component and visualized with a single color and the components inside the ellipse at the bottom right should be grouped into another single component and visualized with another unique color while keeping the rest of the map unchanged.
How can I do so?
Edit 2: I can now group the components desired in a very manual way as follows:
scleft = SelectComponents[
imgbin, #Count < 80 && #Centroid[[1]] < 130 &];
scright =
SelectComponents[imgbin, #Count < 80 && #Centroid[[1]] > 350 &];
and the components for the rest of the parts
mc = MorphologicalComponents[
ImageSubtract[imgbin, ImageAdd[scleft, scright]]];
Now how can I join these components - scleft
, scright
and mc
and get the desired result?
image-processing visualization geography
Below is a map of India (img
).
and I can visualize it in the following way:
imgbin = Binarize@img;
MorphologicalComponents[imgbin] // Colorize
and the result is:
Edit
Following a manual approach, I can isolate the small components:
sc = SelectComponents[imgbin, #Count < 60 &];
However, this gives me
Now I find the coordinates of the centroids:
centroids = ComponentMeasurements[sc, "Centroid"];
This gives me
1 -> 523.425, 182.274, 2 -> 545.125, 182.563, 3 -> 521.089, 154.518,
4 -> 96.2778, 154.722, 5 -> 101.5, 150.625, 6 -> 285.375, 146.667,
7 -> 111.7, 136., 8 -> 517.868, 133.947, 9 -> 91.8846, 134.885,
10 -> 99.3889, 135.167, 11 -> 95.0882, 122.382, 12 -> 531.136, 105.409,
13 -> 535.5, 94., 14 -> 541.4, 92.6, 15 -> 551.833, 93.8333,
16 -> 540.333, 86.5833, 17 -> 564., 63.5, 18 -> 557.929, 61.5,
19 -> 558.833, 55.8333, 20 -> 567.5, 27., 21 -> 575.689, 20.3491
From this information, I think, the grouping can be done. I need to choose two thresholds for the X
coordinates of the centroids. Manually, I can set the thresholds as 100
and 200
. Then, the components having centroids with x < 100
will be grouped into one, the component having the centroid with 100 < x < 200
will be grouped into another one (this component should be discarded as it is already considered as a component earlier) and finally the components having centroids with x > 200
will be grouped into the second one.
However, I wish to group some of the components as shown below:
That is, the components inside the circle at the bottom left should be grouped into a single component and visualized with a single color and the components inside the ellipse at the bottom right should be grouped into another single component and visualized with another unique color while keeping the rest of the map unchanged.
How can I do so?
Edit 2: I can now group the components desired in a very manual way as follows:
scleft = SelectComponents[
imgbin, #Count < 80 && #Centroid[[1]] < 130 &];
scright =
SelectComponents[imgbin, #Count < 80 && #Centroid[[1]] > 350 &];
and the components for the rest of the parts
mc = MorphologicalComponents[
ImageSubtract[imgbin, ImageAdd[scleft, scright]]];
Now how can I join these components - scleft
, scright
and mc
and get the desired result?
image-processing visualization geography
image-processing visualization geography
edited 47 mins ago
asked 3 hours ago
Majis
1,333313
1,333313
What have you tried so far ? Understand your original attempts will help us get started in helping you.
â user6014
3 hours ago
@user6014 I am not sure. Maybe group them by the components' centroid coordinates.
â Majis
3 hours ago
If you post code examples of your best attempt so far it will be a good starting point for someone to build off of and hopefully get you to the next step.
â user6014
3 hours ago
@user6014 see my edit.
â Majis
3 hours ago
1
Majis, may i suggest you re-visit your previous questions and check if any of the answers is worth accepting?
â kglr
1 hour ago
 |Â
show 1 more comment
What have you tried so far ? Understand your original attempts will help us get started in helping you.
â user6014
3 hours ago
@user6014 I am not sure. Maybe group them by the components' centroid coordinates.
â Majis
3 hours ago
If you post code examples of your best attempt so far it will be a good starting point for someone to build off of and hopefully get you to the next step.
â user6014
3 hours ago
@user6014 see my edit.
â Majis
3 hours ago
1
Majis, may i suggest you re-visit your previous questions and check if any of the answers is worth accepting?
â kglr
1 hour ago
What have you tried so far ? Understand your original attempts will help us get started in helping you.
â user6014
3 hours ago
What have you tried so far ? Understand your original attempts will help us get started in helping you.
â user6014
3 hours ago
@user6014 I am not sure. Maybe group them by the components' centroid coordinates.
â Majis
3 hours ago
@user6014 I am not sure. Maybe group them by the components' centroid coordinates.
â Majis
3 hours ago
If you post code examples of your best attempt so far it will be a good starting point for someone to build off of and hopefully get you to the next step.
â user6014
3 hours ago
If you post code examples of your best attempt so far it will be a good starting point for someone to build off of and hopefully get you to the next step.
â user6014
3 hours ago
@user6014 see my edit.
â Majis
3 hours ago
@user6014 see my edit.
â Majis
3 hours ago
1
1
Majis, may i suggest you re-visit your previous questions and check if any of the answers is worth accepting?
â kglr
1 hour ago
Majis, may i suggest you re-visit your previous questions and check if any of the answers is worth accepting?
â kglr
1 hour ago
 |Â
show 1 more comment
2 Answers
2
active
oldest
votes
up vote
5
down vote
Update:
clusters = FindClusters[#[[2, 1]] -> # & /@
ComponentMeasurements[MorphologicalComponents[imgbin],
"Centroid", "Count", #2 < 80 && (#[[1]] < 130 || #[[1]] > 350) &], 2][[All, All, 1]];
Colorize[MorphologicalComponents[imgbin],
ColorRules -> Join @@ (Thread /@ Thread[clusters -> Red, Green])]
Original answer:
clusters = FindClusters[#[[2, 1]] -> # & /@
ComponentMeasurements[imgbin, "Centroid", "Count", #2 < 65 &], 2][[All, All, 1]];
Colorize[MorphologicalComponents[imgbin],
ColorRules -> Join @@ (Thread /@ Thread[clusters -> Red, Green])]
Note: Need further refinement to exclude the red elements on the continent.
see my edit to the question.
â Majis
46 mins ago
@Majis, please see the update.
â kglr
26 mins ago
add a comment |Â
up vote
4
down vote
Another idea is to dilate the image slightly to find 'connected' components.
img = Import["https://i.stack.imgur.com/6wQT9.jpg"];
mask = Binarize[Dilation[img, DiskMatrix[15]]];
comps = MorphologicalComponents[mask];
chain2, chain1, mainland = SortBy[Table[
Binarize[img*Image[1 - Unitize[comps - i]]], i, 3], Total];
Colorize[MorphologicalComponents[mainland, CornerNeighbors -> False]] +
ColorReplace[chain1, White -> Green] +
ColorReplace[chain2, White -> Red]
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
Update:
clusters = FindClusters[#[[2, 1]] -> # & /@
ComponentMeasurements[MorphologicalComponents[imgbin],
"Centroid", "Count", #2 < 80 && (#[[1]] < 130 || #[[1]] > 350) &], 2][[All, All, 1]];
Colorize[MorphologicalComponents[imgbin],
ColorRules -> Join @@ (Thread /@ Thread[clusters -> Red, Green])]
Original answer:
clusters = FindClusters[#[[2, 1]] -> # & /@
ComponentMeasurements[imgbin, "Centroid", "Count", #2 < 65 &], 2][[All, All, 1]];
Colorize[MorphologicalComponents[imgbin],
ColorRules -> Join @@ (Thread /@ Thread[clusters -> Red, Green])]
Note: Need further refinement to exclude the red elements on the continent.
see my edit to the question.
â Majis
46 mins ago
@Majis, please see the update.
â kglr
26 mins ago
add a comment |Â
up vote
5
down vote
Update:
clusters = FindClusters[#[[2, 1]] -> # & /@
ComponentMeasurements[MorphologicalComponents[imgbin],
"Centroid", "Count", #2 < 80 && (#[[1]] < 130 || #[[1]] > 350) &], 2][[All, All, 1]];
Colorize[MorphologicalComponents[imgbin],
ColorRules -> Join @@ (Thread /@ Thread[clusters -> Red, Green])]
Original answer:
clusters = FindClusters[#[[2, 1]] -> # & /@
ComponentMeasurements[imgbin, "Centroid", "Count", #2 < 65 &], 2][[All, All, 1]];
Colorize[MorphologicalComponents[imgbin],
ColorRules -> Join @@ (Thread /@ Thread[clusters -> Red, Green])]
Note: Need further refinement to exclude the red elements on the continent.
see my edit to the question.
â Majis
46 mins ago
@Majis, please see the update.
â kglr
26 mins ago
add a comment |Â
up vote
5
down vote
up vote
5
down vote
Update:
clusters = FindClusters[#[[2, 1]] -> # & /@
ComponentMeasurements[MorphologicalComponents[imgbin],
"Centroid", "Count", #2 < 80 && (#[[1]] < 130 || #[[1]] > 350) &], 2][[All, All, 1]];
Colorize[MorphologicalComponents[imgbin],
ColorRules -> Join @@ (Thread /@ Thread[clusters -> Red, Green])]
Original answer:
clusters = FindClusters[#[[2, 1]] -> # & /@
ComponentMeasurements[imgbin, "Centroid", "Count", #2 < 65 &], 2][[All, All, 1]];
Colorize[MorphologicalComponents[imgbin],
ColorRules -> Join @@ (Thread /@ Thread[clusters -> Red, Green])]
Note: Need further refinement to exclude the red elements on the continent.
Update:
clusters = FindClusters[#[[2, 1]] -> # & /@
ComponentMeasurements[MorphologicalComponents[imgbin],
"Centroid", "Count", #2 < 80 && (#[[1]] < 130 || #[[1]] > 350) &], 2][[All, All, 1]];
Colorize[MorphologicalComponents[imgbin],
ColorRules -> Join @@ (Thread /@ Thread[clusters -> Red, Green])]
Original answer:
clusters = FindClusters[#[[2, 1]] -> # & /@
ComponentMeasurements[imgbin, "Centroid", "Count", #2 < 65 &], 2][[All, All, 1]];
Colorize[MorphologicalComponents[imgbin],
ColorRules -> Join @@ (Thread /@ Thread[clusters -> Red, Green])]
Note: Need further refinement to exclude the red elements on the continent.
edited 31 mins ago
answered 2 hours ago
kglr
165k8188388
165k8188388
see my edit to the question.
â Majis
46 mins ago
@Majis, please see the update.
â kglr
26 mins ago
add a comment |Â
see my edit to the question.
â Majis
46 mins ago
@Majis, please see the update.
â kglr
26 mins ago
see my edit to the question.
â Majis
46 mins ago
see my edit to the question.
â Majis
46 mins ago
@Majis, please see the update.
â kglr
26 mins ago
@Majis, please see the update.
â kglr
26 mins ago
add a comment |Â
up vote
4
down vote
Another idea is to dilate the image slightly to find 'connected' components.
img = Import["https://i.stack.imgur.com/6wQT9.jpg"];
mask = Binarize[Dilation[img, DiskMatrix[15]]];
comps = MorphologicalComponents[mask];
chain2, chain1, mainland = SortBy[Table[
Binarize[img*Image[1 - Unitize[comps - i]]], i, 3], Total];
Colorize[MorphologicalComponents[mainland, CornerNeighbors -> False]] +
ColorReplace[chain1, White -> Green] +
ColorReplace[chain2, White -> Red]
add a comment |Â
up vote
4
down vote
Another idea is to dilate the image slightly to find 'connected' components.
img = Import["https://i.stack.imgur.com/6wQT9.jpg"];
mask = Binarize[Dilation[img, DiskMatrix[15]]];
comps = MorphologicalComponents[mask];
chain2, chain1, mainland = SortBy[Table[
Binarize[img*Image[1 - Unitize[comps - i]]], i, 3], Total];
Colorize[MorphologicalComponents[mainland, CornerNeighbors -> False]] +
ColorReplace[chain1, White -> Green] +
ColorReplace[chain2, White -> Red]
add a comment |Â
up vote
4
down vote
up vote
4
down vote
Another idea is to dilate the image slightly to find 'connected' components.
img = Import["https://i.stack.imgur.com/6wQT9.jpg"];
mask = Binarize[Dilation[img, DiskMatrix[15]]];
comps = MorphologicalComponents[mask];
chain2, chain1, mainland = SortBy[Table[
Binarize[img*Image[1 - Unitize[comps - i]]], i, 3], Total];
Colorize[MorphologicalComponents[mainland, CornerNeighbors -> False]] +
ColorReplace[chain1, White -> Green] +
ColorReplace[chain2, White -> Red]
Another idea is to dilate the image slightly to find 'connected' components.
img = Import["https://i.stack.imgur.com/6wQT9.jpg"];
mask = Binarize[Dilation[img, DiskMatrix[15]]];
comps = MorphologicalComponents[mask];
chain2, chain1, mainland = SortBy[Table[
Binarize[img*Image[1 - Unitize[comps - i]]], i, 3], Total];
Colorize[MorphologicalComponents[mainland, CornerNeighbors -> False]] +
ColorReplace[chain1, White -> Green] +
ColorReplace[chain2, White -> Red]
answered 25 mins ago
Chip Hurst
19.3k15485
19.3k15485
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f183689%2fcoloring-a-map-of-india%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
What have you tried so far ? Understand your original attempts will help us get started in helping you.
â user6014
3 hours ago
@user6014 I am not sure. Maybe group them by the components' centroid coordinates.
â Majis
3 hours ago
If you post code examples of your best attempt so far it will be a good starting point for someone to build off of and hopefully get you to the next step.
â user6014
3 hours ago
@user6014 see my edit.
â Majis
3 hours ago
1
Majis, may i suggest you re-visit your previous questions and check if any of the answers is worth accepting?
â kglr
1 hour ago