Determine maximum and minimum pixel value to draw bounding box
Given an image with semantic map,


In python, How can I draw a bounding-box around the person standing for instance?
I've done some research and understood that I need to choose the maximum and minimum pixel value to get the bounding box information. But I don't understand how to implement this.
python image-processing
add a comment |
Given an image with semantic map,


In python, How can I draw a bounding-box around the person standing for instance?
I've done some research and understood that I need to choose the maximum and minimum pixel value to get the bounding box information. But I don't understand how to implement this.
python image-processing
add a comment |
Given an image with semantic map,


In python, How can I draw a bounding-box around the person standing for instance?
I've done some research and understood that I need to choose the maximum and minimum pixel value to get the bounding box information. But I don't understand how to implement this.
python image-processing
Given an image with semantic map,


In python, How can I draw a bounding-box around the person standing for instance?
I've done some research and understood that I need to choose the maximum and minimum pixel value to get the bounding box information. But I don't understand how to implement this.
python image-processing
python image-processing
asked 9 hours ago
user3641381
455617
455617
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
- Redraw the object you want to box in unique for that semantic map color. For instance I've used green:

- Run following script:
.
from PIL import Image, ImageDraw
IMAGE = 't5XM4.png'
IMAGE_MAP = 'Gz8b7.png'
IMAGE_OUTPUT = 'Result.png'
GREEN = (0, 255, 0)
OFFSET = 10
image_map = Image.open(IMAGE_MAP)
image = Image.open(IMAGE)
pixels = image_map.load()
size_sm = image_map.size
size = image.size
ratio = (size_sm[0]/size[0], size_sm[1]/size[1])
x_list =
y_list =
for x in range(size_sm[0]):
for y in range(size_sm[1]):
if pixels[x, y] == GREEN:
x_list.append(x)
y_list.append(y)
draw = ImageDraw.Draw(image)
draw.rectangle(((min(x_list)/ratio[0]-OFFSET, min(y_list)/ratio[1]-OFFSET),
(max(x_list)/ratio[0]+OFFSET,max(y_list)/ratio[1]+OFFSET)),
width=5, outline=GREEN)
image.save(IMAGE_OUTPUT, 'PNG')
- You've got following image at the end:

add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53942508%2fdetermine-maximum-and-minimum-pixel-value-to-draw-bounding-box%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
- Redraw the object you want to box in unique for that semantic map color. For instance I've used green:

- Run following script:
.
from PIL import Image, ImageDraw
IMAGE = 't5XM4.png'
IMAGE_MAP = 'Gz8b7.png'
IMAGE_OUTPUT = 'Result.png'
GREEN = (0, 255, 0)
OFFSET = 10
image_map = Image.open(IMAGE_MAP)
image = Image.open(IMAGE)
pixels = image_map.load()
size_sm = image_map.size
size = image.size
ratio = (size_sm[0]/size[0], size_sm[1]/size[1])
x_list =
y_list =
for x in range(size_sm[0]):
for y in range(size_sm[1]):
if pixels[x, y] == GREEN:
x_list.append(x)
y_list.append(y)
draw = ImageDraw.Draw(image)
draw.rectangle(((min(x_list)/ratio[0]-OFFSET, min(y_list)/ratio[1]-OFFSET),
(max(x_list)/ratio[0]+OFFSET,max(y_list)/ratio[1]+OFFSET)),
width=5, outline=GREEN)
image.save(IMAGE_OUTPUT, 'PNG')
- You've got following image at the end:

add a comment |
- Redraw the object you want to box in unique for that semantic map color. For instance I've used green:

- Run following script:
.
from PIL import Image, ImageDraw
IMAGE = 't5XM4.png'
IMAGE_MAP = 'Gz8b7.png'
IMAGE_OUTPUT = 'Result.png'
GREEN = (0, 255, 0)
OFFSET = 10
image_map = Image.open(IMAGE_MAP)
image = Image.open(IMAGE)
pixels = image_map.load()
size_sm = image_map.size
size = image.size
ratio = (size_sm[0]/size[0], size_sm[1]/size[1])
x_list =
y_list =
for x in range(size_sm[0]):
for y in range(size_sm[1]):
if pixels[x, y] == GREEN:
x_list.append(x)
y_list.append(y)
draw = ImageDraw.Draw(image)
draw.rectangle(((min(x_list)/ratio[0]-OFFSET, min(y_list)/ratio[1]-OFFSET),
(max(x_list)/ratio[0]+OFFSET,max(y_list)/ratio[1]+OFFSET)),
width=5, outline=GREEN)
image.save(IMAGE_OUTPUT, 'PNG')
- You've got following image at the end:

add a comment |
- Redraw the object you want to box in unique for that semantic map color. For instance I've used green:

- Run following script:
.
from PIL import Image, ImageDraw
IMAGE = 't5XM4.png'
IMAGE_MAP = 'Gz8b7.png'
IMAGE_OUTPUT = 'Result.png'
GREEN = (0, 255, 0)
OFFSET = 10
image_map = Image.open(IMAGE_MAP)
image = Image.open(IMAGE)
pixels = image_map.load()
size_sm = image_map.size
size = image.size
ratio = (size_sm[0]/size[0], size_sm[1]/size[1])
x_list =
y_list =
for x in range(size_sm[0]):
for y in range(size_sm[1]):
if pixels[x, y] == GREEN:
x_list.append(x)
y_list.append(y)
draw = ImageDraw.Draw(image)
draw.rectangle(((min(x_list)/ratio[0]-OFFSET, min(y_list)/ratio[1]-OFFSET),
(max(x_list)/ratio[0]+OFFSET,max(y_list)/ratio[1]+OFFSET)),
width=5, outline=GREEN)
image.save(IMAGE_OUTPUT, 'PNG')
- You've got following image at the end:

- Redraw the object you want to box in unique for that semantic map color. For instance I've used green:

- Run following script:
.
from PIL import Image, ImageDraw
IMAGE = 't5XM4.png'
IMAGE_MAP = 'Gz8b7.png'
IMAGE_OUTPUT = 'Result.png'
GREEN = (0, 255, 0)
OFFSET = 10
image_map = Image.open(IMAGE_MAP)
image = Image.open(IMAGE)
pixels = image_map.load()
size_sm = image_map.size
size = image.size
ratio = (size_sm[0]/size[0], size_sm[1]/size[1])
x_list =
y_list =
for x in range(size_sm[0]):
for y in range(size_sm[1]):
if pixels[x, y] == GREEN:
x_list.append(x)
y_list.append(y)
draw = ImageDraw.Draw(image)
draw.rectangle(((min(x_list)/ratio[0]-OFFSET, min(y_list)/ratio[1]-OFFSET),
(max(x_list)/ratio[0]+OFFSET,max(y_list)/ratio[1]+OFFSET)),
width=5, outline=GREEN)
image.save(IMAGE_OUTPUT, 'PNG')
- You've got following image at the end:

edited 4 hours ago
answered 4 hours ago
Alderven
518317
518317
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53942508%2fdetermine-maximum-and-minimum-pixel-value-to-draw-bounding-box%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown