Plotting positive and negative pixels of image separately on subplots
up vote
0
down vote
favorite
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 |
up vote
0
down vote
favorite
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 |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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 at 1:42
ViniLL
196
196
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
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 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 at 13:40
Ok got you, thanks.
– ViniLL
Nov 15 at 18:32
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
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 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 at 13:40
Ok got you, thanks.
– ViniLL
Nov 15 at 18:32
add a comment |
up vote
0
down vote
accepted
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 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 at 13:40
Ok got you, thanks.
– ViniLL
Nov 15 at 18:32
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
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 at 13:39
answered Nov 15 at 2:40
ImportanceOfBeingErnest
123k10125201
123k10125201
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 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 at 13:40
Ok got you, thanks.
– ViniLL
Nov 15 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 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 at 13:40
Ok got you, thanks.
– ViniLL
Nov 15 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 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 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 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 at 13:40
Ok got you, thanks.
– ViniLL
Nov 15 at 18:32
Ok got you, thanks.
– ViniLL
Nov 15 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.
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%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