Plotting positive and negative pixels of image separately on subplots
Suppose have an image like this, that consists of two images, 1 and 6 which are kind of superimposed on each other, if you look closely at it.
So, I need to visualize each of these digits separately by having all positive pixels of original image in one image, and all negative pixels in the second one. Is there any way to achieve that in python using matplotlib.pyplot without messing up with the structure of the image? Basically, I need all the white color pixels to be plotted separately from the black color pixels.
python matplotlib image-processing plot pixel
add a comment |
Suppose have an image like this, that consists of two images, 1 and 6 which are kind of superimposed on each other, if you look closely at it.
So, I need to visualize each of these digits separately by having all positive pixels of original image in one image, and all negative pixels in the second one. Is there any way to achieve that in python using matplotlib.pyplot without messing up with the structure of the image? Basically, I need all the white color pixels to be plotted separately from the black color pixels.
python matplotlib image-processing plot pixel
add a comment |
Suppose have an image like this, that consists of two images, 1 and 6 which are kind of superimposed on each other, if you look closely at it.
So, I need to visualize each of these digits separately by having all positive pixels of original image in one image, and all negative pixels in the second one. Is there any way to achieve that in python using matplotlib.pyplot without messing up with the structure of the image? Basically, I need all the white color pixels to be plotted separately from the black color pixels.
python matplotlib image-processing plot pixel
Suppose have an image like this, that consists of two images, 1 and 6 which are kind of superimposed on each other, if you look closely at it.
So, I need to visualize each of these digits separately by having all positive pixels of original image in one image, and all negative pixels in the second one. Is there any way to achieve that in python using matplotlib.pyplot without messing up with the structure of the image? Basically, I need all the white color pixels to be plotted separately from the black color pixels.
python matplotlib image-processing plot pixel
python matplotlib image-processing plot pixel
asked Nov 15 '18 at 1:42
ViniLLViniLL
216
216
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You may set all values above or below some threshold to nan
, such that they won't appear in the final image.
The following code leaves out the range between 0.4 and 0.6 completely. The yellow background is chosen to show that there are no pixels in that area.
import numpy as np
import matplotlib.pyplot as plt
img = plt.imread("grayscaleimage.png")[:,:,0]
white = np.copy(img)
white[white<0.6] = np.nan
dark = np.copy(img)
dark[dark>0.4] = np.nan
fig = plt.figure()
ax0 = fig.add_subplot(211)
ax1 = fig.add_subplot(223)
ax2 = fig.add_subplot(224)
ax0.imshow(img, vmin=0, vmax=1, cmap="Greys")
ax1.imshow(white, vmin=0, vmax=1, cmap="Greys")
ax2.imshow(dark, vmin=0, vmax=1, cmap="Greys")
for ax in (ax1,ax2):
ax.set_facecolor("gold")
plt.show()
Here is the test image used in the above:
(right click, save as...)
Thanks a lot, it worked pretty well! I had to change some values though, but I got the point. Could you also share where did you get your testing image? it looks much sharper and it is very relevant to my ML perceptron algorithm that I am implementing
– ViniLL
Nov 15 '18 at 7:42
I added the test image. It's created via inkscape by placing a white 1 and a black 6 on gray background.
– ImportanceOfBeingErnest
Nov 15 '18 at 13:40
Ok got you, thanks.
– ViniLL
Nov 15 '18 at 18:32
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%2f53311276%2fplotting-positive-and-negative-pixels-of-image-separately-on-subplots%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
You may set all values above or below some threshold to nan
, such that they won't appear in the final image.
The following code leaves out the range between 0.4 and 0.6 completely. The yellow background is chosen to show that there are no pixels in that area.
import numpy as np
import matplotlib.pyplot as plt
img = plt.imread("grayscaleimage.png")[:,:,0]
white = np.copy(img)
white[white<0.6] = np.nan
dark = np.copy(img)
dark[dark>0.4] = np.nan
fig = plt.figure()
ax0 = fig.add_subplot(211)
ax1 = fig.add_subplot(223)
ax2 = fig.add_subplot(224)
ax0.imshow(img, vmin=0, vmax=1, cmap="Greys")
ax1.imshow(white, vmin=0, vmax=1, cmap="Greys")
ax2.imshow(dark, vmin=0, vmax=1, cmap="Greys")
for ax in (ax1,ax2):
ax.set_facecolor("gold")
plt.show()
Here is the test image used in the above:
(right click, save as...)
Thanks a lot, it worked pretty well! I had to change some values though, but I got the point. Could you also share where did you get your testing image? it looks much sharper and it is very relevant to my ML perceptron algorithm that I am implementing
– ViniLL
Nov 15 '18 at 7:42
I added the test image. It's created via inkscape by placing a white 1 and a black 6 on gray background.
– ImportanceOfBeingErnest
Nov 15 '18 at 13:40
Ok got you, thanks.
– ViniLL
Nov 15 '18 at 18:32
add a comment |
You may set all values above or below some threshold to nan
, such that they won't appear in the final image.
The following code leaves out the range between 0.4 and 0.6 completely. The yellow background is chosen to show that there are no pixels in that area.
import numpy as np
import matplotlib.pyplot as plt
img = plt.imread("grayscaleimage.png")[:,:,0]
white = np.copy(img)
white[white<0.6] = np.nan
dark = np.copy(img)
dark[dark>0.4] = np.nan
fig = plt.figure()
ax0 = fig.add_subplot(211)
ax1 = fig.add_subplot(223)
ax2 = fig.add_subplot(224)
ax0.imshow(img, vmin=0, vmax=1, cmap="Greys")
ax1.imshow(white, vmin=0, vmax=1, cmap="Greys")
ax2.imshow(dark, vmin=0, vmax=1, cmap="Greys")
for ax in (ax1,ax2):
ax.set_facecolor("gold")
plt.show()
Here is the test image used in the above:
(right click, save as...)
Thanks a lot, it worked pretty well! I had to change some values though, but I got the point. Could you also share where did you get your testing image? it looks much sharper and it is very relevant to my ML perceptron algorithm that I am implementing
– ViniLL
Nov 15 '18 at 7:42
I added the test image. It's created via inkscape by placing a white 1 and a black 6 on gray background.
– ImportanceOfBeingErnest
Nov 15 '18 at 13:40
Ok got you, thanks.
– ViniLL
Nov 15 '18 at 18:32
add a comment |
You may set all values above or below some threshold to nan
, such that they won't appear in the final image.
The following code leaves out the range between 0.4 and 0.6 completely. The yellow background is chosen to show that there are no pixels in that area.
import numpy as np
import matplotlib.pyplot as plt
img = plt.imread("grayscaleimage.png")[:,:,0]
white = np.copy(img)
white[white<0.6] = np.nan
dark = np.copy(img)
dark[dark>0.4] = np.nan
fig = plt.figure()
ax0 = fig.add_subplot(211)
ax1 = fig.add_subplot(223)
ax2 = fig.add_subplot(224)
ax0.imshow(img, vmin=0, vmax=1, cmap="Greys")
ax1.imshow(white, vmin=0, vmax=1, cmap="Greys")
ax2.imshow(dark, vmin=0, vmax=1, cmap="Greys")
for ax in (ax1,ax2):
ax.set_facecolor("gold")
plt.show()
Here is the test image used in the above:
(right click, save as...)
You may set all values above or below some threshold to nan
, such that they won't appear in the final image.
The following code leaves out the range between 0.4 and 0.6 completely. The yellow background is chosen to show that there are no pixels in that area.
import numpy as np
import matplotlib.pyplot as plt
img = plt.imread("grayscaleimage.png")[:,:,0]
white = np.copy(img)
white[white<0.6] = np.nan
dark = np.copy(img)
dark[dark>0.4] = np.nan
fig = plt.figure()
ax0 = fig.add_subplot(211)
ax1 = fig.add_subplot(223)
ax2 = fig.add_subplot(224)
ax0.imshow(img, vmin=0, vmax=1, cmap="Greys")
ax1.imshow(white, vmin=0, vmax=1, cmap="Greys")
ax2.imshow(dark, vmin=0, vmax=1, cmap="Greys")
for ax in (ax1,ax2):
ax.set_facecolor("gold")
plt.show()
Here is the test image used in the above:
(right click, save as...)
edited Nov 15 '18 at 13:39
answered Nov 15 '18 at 2:40
ImportanceOfBeingErnestImportanceOfBeingErnest
135k13151226
135k13151226
Thanks a lot, it worked pretty well! I had to change some values though, but I got the point. Could you also share where did you get your testing image? it looks much sharper and it is very relevant to my ML perceptron algorithm that I am implementing
– ViniLL
Nov 15 '18 at 7:42
I added the test image. It's created via inkscape by placing a white 1 and a black 6 on gray background.
– ImportanceOfBeingErnest
Nov 15 '18 at 13:40
Ok got you, thanks.
– ViniLL
Nov 15 '18 at 18:32
add a comment |
Thanks a lot, it worked pretty well! I had to change some values though, but I got the point. Could you also share where did you get your testing image? it looks much sharper and it is very relevant to my ML perceptron algorithm that I am implementing
– ViniLL
Nov 15 '18 at 7:42
I added the test image. It's created via inkscape by placing a white 1 and a black 6 on gray background.
– ImportanceOfBeingErnest
Nov 15 '18 at 13:40
Ok got you, thanks.
– ViniLL
Nov 15 '18 at 18:32
Thanks a lot, it worked pretty well! I had to change some values though, but I got the point. Could you also share where did you get your testing image? it looks much sharper and it is very relevant to my ML perceptron algorithm that I am implementing
– ViniLL
Nov 15 '18 at 7:42
Thanks a lot, it worked pretty well! I had to change some values though, but I got the point. Could you also share where did you get your testing image? it looks much sharper and it is very relevant to my ML perceptron algorithm that I am implementing
– ViniLL
Nov 15 '18 at 7:42
I added the test image. It's created via inkscape by placing a white 1 and a black 6 on gray background.
– ImportanceOfBeingErnest
Nov 15 '18 at 13:40
I added the test image. It's created via inkscape by placing a white 1 and a black 6 on gray background.
– ImportanceOfBeingErnest
Nov 15 '18 at 13:40
Ok got you, thanks.
– ViniLL
Nov 15 '18 at 18:32
Ok got you, thanks.
– ViniLL
Nov 15 '18 at 18:32
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.
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%2f53311276%2fplotting-positive-and-negative-pixels-of-image-separately-on-subplots%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