Matplotlib: Missing channel using imread
When I try to load an image that has three channels with matplotlib it only has one channel when I issue the numpy shape
command. This shows the following image:
Here is the code I used:
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np
img = mpimg.imread('dolphin.png')
plt.imshow(img)
plt.show()
img.shape
(320, 500)
I also followed the matplotlib image tutorial which uses the same commands as above.
Loading the image with opencv the result is an image with three channels, as expected.
import cv2
imgcv = cv2.imread('dolphin.png')
plt.imshow(imgcv)
plt.show()
imgcv.shape
(320, 500, 3)
I am using Python 3.5.6 with anaconda.
Here is a short output of the conda list
command:
...
matplotlib 3.0.0
...
opencv3 3.1.0
...
pillow 5.2.0
...
The original image I used:
Am I missing a package or is there another command to load a *.png file? Everything seems to work with *.jpg images
python matplotlib png jpeg imread
|
show 2 more comments
When I try to load an image that has three channels with matplotlib it only has one channel when I issue the numpy shape
command. This shows the following image:
Here is the code I used:
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np
img = mpimg.imread('dolphin.png')
plt.imshow(img)
plt.show()
img.shape
(320, 500)
I also followed the matplotlib image tutorial which uses the same commands as above.
Loading the image with opencv the result is an image with three channels, as expected.
import cv2
imgcv = cv2.imread('dolphin.png')
plt.imshow(imgcv)
plt.show()
imgcv.shape
(320, 500, 3)
I am using Python 3.5.6 with anaconda.
Here is a short output of the conda list
command:
...
matplotlib 3.0.0
...
opencv3 3.1.0
...
pillow 5.2.0
...
The original image I used:
Am I missing a package or is there another command to load a *.png file? Everything seems to work with *.jpg images
python matplotlib png jpeg imread
dolphin.png
is a grey scale image with a single channel. Is your question how to duplicate those channels to have a grey RGB image?
– ImportanceOfBeingErnest
Nov 14 '18 at 21:16
No it has three channels. Please look at the output ofimgcv.shape
. It is(320, 500, 3)
– evolved
Nov 14 '18 at 21:17
There seems to be something wrong with theimread
command of matplotlib (or how I use it) as it results in an image with only one channel.img.shape
yields(320, 500)
– evolved
Nov 14 '18 at 21:21
So you meancv2.imread
is more trustworthy thanplt.imread
? I guess we can find out if you provide the original image.
– ImportanceOfBeingErnest
Nov 14 '18 at 21:35
Yes, thats what I see as a result. However, I expect thatplt.imread
also results in a numpy array with three channels. Thanks for your help, I provided the original image. I also tested with the png image from the matplotlib tutorial: matplotlib.org/_images/stinkbug.png which is also missing two channels when reading withplt.imread
– evolved
Nov 14 '18 at 21:50
|
show 2 more comments
When I try to load an image that has three channels with matplotlib it only has one channel when I issue the numpy shape
command. This shows the following image:
Here is the code I used:
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np
img = mpimg.imread('dolphin.png')
plt.imshow(img)
plt.show()
img.shape
(320, 500)
I also followed the matplotlib image tutorial which uses the same commands as above.
Loading the image with opencv the result is an image with three channels, as expected.
import cv2
imgcv = cv2.imread('dolphin.png')
plt.imshow(imgcv)
plt.show()
imgcv.shape
(320, 500, 3)
I am using Python 3.5.6 with anaconda.
Here is a short output of the conda list
command:
...
matplotlib 3.0.0
...
opencv3 3.1.0
...
pillow 5.2.0
...
The original image I used:
Am I missing a package or is there another command to load a *.png file? Everything seems to work with *.jpg images
python matplotlib png jpeg imread
When I try to load an image that has three channels with matplotlib it only has one channel when I issue the numpy shape
command. This shows the following image:
Here is the code I used:
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np
img = mpimg.imread('dolphin.png')
plt.imshow(img)
plt.show()
img.shape
(320, 500)
I also followed the matplotlib image tutorial which uses the same commands as above.
Loading the image with opencv the result is an image with three channels, as expected.
import cv2
imgcv = cv2.imread('dolphin.png')
plt.imshow(imgcv)
plt.show()
imgcv.shape
(320, 500, 3)
I am using Python 3.5.6 with anaconda.
Here is a short output of the conda list
command:
...
matplotlib 3.0.0
...
opencv3 3.1.0
...
pillow 5.2.0
...
The original image I used:
Am I missing a package or is there another command to load a *.png file? Everything seems to work with *.jpg images
python matplotlib png jpeg imread
python matplotlib png jpeg imread
edited Nov 14 '18 at 21:48
evolved
asked Nov 14 '18 at 21:12
evolvedevolved
397519
397519
dolphin.png
is a grey scale image with a single channel. Is your question how to duplicate those channels to have a grey RGB image?
– ImportanceOfBeingErnest
Nov 14 '18 at 21:16
No it has three channels. Please look at the output ofimgcv.shape
. It is(320, 500, 3)
– evolved
Nov 14 '18 at 21:17
There seems to be something wrong with theimread
command of matplotlib (or how I use it) as it results in an image with only one channel.img.shape
yields(320, 500)
– evolved
Nov 14 '18 at 21:21
So you meancv2.imread
is more trustworthy thanplt.imread
? I guess we can find out if you provide the original image.
– ImportanceOfBeingErnest
Nov 14 '18 at 21:35
Yes, thats what I see as a result. However, I expect thatplt.imread
also results in a numpy array with three channels. Thanks for your help, I provided the original image. I also tested with the png image from the matplotlib tutorial: matplotlib.org/_images/stinkbug.png which is also missing two channels when reading withplt.imread
– evolved
Nov 14 '18 at 21:50
|
show 2 more comments
dolphin.png
is a grey scale image with a single channel. Is your question how to duplicate those channels to have a grey RGB image?
– ImportanceOfBeingErnest
Nov 14 '18 at 21:16
No it has three channels. Please look at the output ofimgcv.shape
. It is(320, 500, 3)
– evolved
Nov 14 '18 at 21:17
There seems to be something wrong with theimread
command of matplotlib (or how I use it) as it results in an image with only one channel.img.shape
yields(320, 500)
– evolved
Nov 14 '18 at 21:21
So you meancv2.imread
is more trustworthy thanplt.imread
? I guess we can find out if you provide the original image.
– ImportanceOfBeingErnest
Nov 14 '18 at 21:35
Yes, thats what I see as a result. However, I expect thatplt.imread
also results in a numpy array with three channels. Thanks for your help, I provided the original image. I also tested with the png image from the matplotlib tutorial: matplotlib.org/_images/stinkbug.png which is also missing two channels when reading withplt.imread
– evolved
Nov 14 '18 at 21:50
dolphin.png
is a grey scale image with a single channel. Is your question how to duplicate those channels to have a grey RGB image?– ImportanceOfBeingErnest
Nov 14 '18 at 21:16
dolphin.png
is a grey scale image with a single channel. Is your question how to duplicate those channels to have a grey RGB image?– ImportanceOfBeingErnest
Nov 14 '18 at 21:16
No it has three channels. Please look at the output of
imgcv.shape
. It is (320, 500, 3)
– evolved
Nov 14 '18 at 21:17
No it has three channels. Please look at the output of
imgcv.shape
. It is (320, 500, 3)
– evolved
Nov 14 '18 at 21:17
There seems to be something wrong with the
imread
command of matplotlib (or how I use it) as it results in an image with only one channel. img.shape
yields (320, 500)
– evolved
Nov 14 '18 at 21:21
There seems to be something wrong with the
imread
command of matplotlib (or how I use it) as it results in an image with only one channel. img.shape
yields (320, 500)
– evolved
Nov 14 '18 at 21:21
So you mean
cv2.imread
is more trustworthy than plt.imread
? I guess we can find out if you provide the original image.– ImportanceOfBeingErnest
Nov 14 '18 at 21:35
So you mean
cv2.imread
is more trustworthy than plt.imread
? I guess we can find out if you provide the original image.– ImportanceOfBeingErnest
Nov 14 '18 at 21:35
Yes, thats what I see as a result. However, I expect that
plt.imread
also results in a numpy array with three channels. Thanks for your help, I provided the original image. I also tested with the png image from the matplotlib tutorial: matplotlib.org/_images/stinkbug.png which is also missing two channels when reading with plt.imread
– evolved
Nov 14 '18 at 21:50
Yes, thats what I see as a result. However, I expect that
plt.imread
also results in a numpy array with three channels. Thanks for your help, I provided the original image. I also tested with the png image from the matplotlib tutorial: matplotlib.org/_images/stinkbug.png which is also missing two channels when reading with plt.imread
– evolved
Nov 14 '18 at 21:50
|
show 2 more comments
1 Answer
1
active
oldest
votes
As I see it, matplotlib's imread
correctly reads in the image. If the image contains only a single channel, the resulting numpy array will be 2D. If the image contains 3 or 4 channels, the numpy array will be 3D.
Taking the dolphin image from the question you get
plt.imread("https://i.stack.imgur.com/cInHj.png").shape
> (320, 500)
Concerning the stinkbug image from the matplotlib documentation there is indeed a little problem. The image you see is a grey scale image as well,
plt.imread("https://matplotlib.org/_images/stinkbug.png").shape
> (375, 500)
However the tutorial claims it to be a 3 channel image. This is correct from the point of view of the tutorial, because it takes the image from the doc
on the github repository folder.
plt.imread("https://raw.githubusercontent.com/matplotlib/matplotlib/master/doc/_static/stinkbug.png").shape
> (375, 500, 3)
The problem is that the documentation is built through sphinx and sphinx-gallery and in addition may use some other libraries. In the course of this, the image is not copied in its raw format to the output folder. This problem has been reported already here, the reason is not yet fully tracked down.
In any case, the remaining open question is then, why does cv2.imread
give you a 3D array for a greyscale image?
From the OpenCV imread
documentation:
Second argument is a flag which specifies the way image should be read.
- cv2.IMREAD_COLOR : Loads a color image. Any transparency of image will be neglected. It is the default flag.
- cv2.IMREAD_GRAYSCALE : Loads image in grayscale mode
- cv2.IMREAD_UNCHANGED : Loads image as such including alpha channel
Note Instead of these three flags, you can simply pass integers 1, 0 or -1 respectively.
So here you need to specify yourself, which mode you want to use.
Let's verify:
import cv2
import urllib.request as req
dolphinurl ="https://i.stack.imgur.com/cInHj.png"
stinkbugweburl = "https://matplotlib.org/_images/stinkbug.png"
stinkbuggiturl = "https://raw.githubusercontent.com/matplotlib/matplotlib/master/doc/_static/stinkbug.png"
def printshape(url, **kw):
req.urlretrieve(url, "image_name.png")
im = cv2.imread("image_name.png", **kw)
print(im.shape)
printshape(dolphinurl)
printshape(stinkbugweburl)
printshape(stinkbugweburl)
This prints
(320, 500, 3)
(375, 500, 3)
(375, 500, 3)
while if you specify greyscale,
printshape(dolphinurl,0)
printshape(stinkbugweburl,0)
printshape(stinkbugweburl,0)
it'll print
(320, 500)
(375, 500)
(375, 500)
In that sense it's up to the user to decide how they want to read in the image.
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%2f53308792%2fmatplotlib-missing-channel-using-imread%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
As I see it, matplotlib's imread
correctly reads in the image. If the image contains only a single channel, the resulting numpy array will be 2D. If the image contains 3 or 4 channels, the numpy array will be 3D.
Taking the dolphin image from the question you get
plt.imread("https://i.stack.imgur.com/cInHj.png").shape
> (320, 500)
Concerning the stinkbug image from the matplotlib documentation there is indeed a little problem. The image you see is a grey scale image as well,
plt.imread("https://matplotlib.org/_images/stinkbug.png").shape
> (375, 500)
However the tutorial claims it to be a 3 channel image. This is correct from the point of view of the tutorial, because it takes the image from the doc
on the github repository folder.
plt.imread("https://raw.githubusercontent.com/matplotlib/matplotlib/master/doc/_static/stinkbug.png").shape
> (375, 500, 3)
The problem is that the documentation is built through sphinx and sphinx-gallery and in addition may use some other libraries. In the course of this, the image is not copied in its raw format to the output folder. This problem has been reported already here, the reason is not yet fully tracked down.
In any case, the remaining open question is then, why does cv2.imread
give you a 3D array for a greyscale image?
From the OpenCV imread
documentation:
Second argument is a flag which specifies the way image should be read.
- cv2.IMREAD_COLOR : Loads a color image. Any transparency of image will be neglected. It is the default flag.
- cv2.IMREAD_GRAYSCALE : Loads image in grayscale mode
- cv2.IMREAD_UNCHANGED : Loads image as such including alpha channel
Note Instead of these three flags, you can simply pass integers 1, 0 or -1 respectively.
So here you need to specify yourself, which mode you want to use.
Let's verify:
import cv2
import urllib.request as req
dolphinurl ="https://i.stack.imgur.com/cInHj.png"
stinkbugweburl = "https://matplotlib.org/_images/stinkbug.png"
stinkbuggiturl = "https://raw.githubusercontent.com/matplotlib/matplotlib/master/doc/_static/stinkbug.png"
def printshape(url, **kw):
req.urlretrieve(url, "image_name.png")
im = cv2.imread("image_name.png", **kw)
print(im.shape)
printshape(dolphinurl)
printshape(stinkbugweburl)
printshape(stinkbugweburl)
This prints
(320, 500, 3)
(375, 500, 3)
(375, 500, 3)
while if you specify greyscale,
printshape(dolphinurl,0)
printshape(stinkbugweburl,0)
printshape(stinkbugweburl,0)
it'll print
(320, 500)
(375, 500)
(375, 500)
In that sense it's up to the user to decide how they want to read in the image.
add a comment |
As I see it, matplotlib's imread
correctly reads in the image. If the image contains only a single channel, the resulting numpy array will be 2D. If the image contains 3 or 4 channels, the numpy array will be 3D.
Taking the dolphin image from the question you get
plt.imread("https://i.stack.imgur.com/cInHj.png").shape
> (320, 500)
Concerning the stinkbug image from the matplotlib documentation there is indeed a little problem. The image you see is a grey scale image as well,
plt.imread("https://matplotlib.org/_images/stinkbug.png").shape
> (375, 500)
However the tutorial claims it to be a 3 channel image. This is correct from the point of view of the tutorial, because it takes the image from the doc
on the github repository folder.
plt.imread("https://raw.githubusercontent.com/matplotlib/matplotlib/master/doc/_static/stinkbug.png").shape
> (375, 500, 3)
The problem is that the documentation is built through sphinx and sphinx-gallery and in addition may use some other libraries. In the course of this, the image is not copied in its raw format to the output folder. This problem has been reported already here, the reason is not yet fully tracked down.
In any case, the remaining open question is then, why does cv2.imread
give you a 3D array for a greyscale image?
From the OpenCV imread
documentation:
Second argument is a flag which specifies the way image should be read.
- cv2.IMREAD_COLOR : Loads a color image. Any transparency of image will be neglected. It is the default flag.
- cv2.IMREAD_GRAYSCALE : Loads image in grayscale mode
- cv2.IMREAD_UNCHANGED : Loads image as such including alpha channel
Note Instead of these three flags, you can simply pass integers 1, 0 or -1 respectively.
So here you need to specify yourself, which mode you want to use.
Let's verify:
import cv2
import urllib.request as req
dolphinurl ="https://i.stack.imgur.com/cInHj.png"
stinkbugweburl = "https://matplotlib.org/_images/stinkbug.png"
stinkbuggiturl = "https://raw.githubusercontent.com/matplotlib/matplotlib/master/doc/_static/stinkbug.png"
def printshape(url, **kw):
req.urlretrieve(url, "image_name.png")
im = cv2.imread("image_name.png", **kw)
print(im.shape)
printshape(dolphinurl)
printshape(stinkbugweburl)
printshape(stinkbugweburl)
This prints
(320, 500, 3)
(375, 500, 3)
(375, 500, 3)
while if you specify greyscale,
printshape(dolphinurl,0)
printshape(stinkbugweburl,0)
printshape(stinkbugweburl,0)
it'll print
(320, 500)
(375, 500)
(375, 500)
In that sense it's up to the user to decide how they want to read in the image.
add a comment |
As I see it, matplotlib's imread
correctly reads in the image. If the image contains only a single channel, the resulting numpy array will be 2D. If the image contains 3 or 4 channels, the numpy array will be 3D.
Taking the dolphin image from the question you get
plt.imread("https://i.stack.imgur.com/cInHj.png").shape
> (320, 500)
Concerning the stinkbug image from the matplotlib documentation there is indeed a little problem. The image you see is a grey scale image as well,
plt.imread("https://matplotlib.org/_images/stinkbug.png").shape
> (375, 500)
However the tutorial claims it to be a 3 channel image. This is correct from the point of view of the tutorial, because it takes the image from the doc
on the github repository folder.
plt.imread("https://raw.githubusercontent.com/matplotlib/matplotlib/master/doc/_static/stinkbug.png").shape
> (375, 500, 3)
The problem is that the documentation is built through sphinx and sphinx-gallery and in addition may use some other libraries. In the course of this, the image is not copied in its raw format to the output folder. This problem has been reported already here, the reason is not yet fully tracked down.
In any case, the remaining open question is then, why does cv2.imread
give you a 3D array for a greyscale image?
From the OpenCV imread
documentation:
Second argument is a flag which specifies the way image should be read.
- cv2.IMREAD_COLOR : Loads a color image. Any transparency of image will be neglected. It is the default flag.
- cv2.IMREAD_GRAYSCALE : Loads image in grayscale mode
- cv2.IMREAD_UNCHANGED : Loads image as such including alpha channel
Note Instead of these three flags, you can simply pass integers 1, 0 or -1 respectively.
So here you need to specify yourself, which mode you want to use.
Let's verify:
import cv2
import urllib.request as req
dolphinurl ="https://i.stack.imgur.com/cInHj.png"
stinkbugweburl = "https://matplotlib.org/_images/stinkbug.png"
stinkbuggiturl = "https://raw.githubusercontent.com/matplotlib/matplotlib/master/doc/_static/stinkbug.png"
def printshape(url, **kw):
req.urlretrieve(url, "image_name.png")
im = cv2.imread("image_name.png", **kw)
print(im.shape)
printshape(dolphinurl)
printshape(stinkbugweburl)
printshape(stinkbugweburl)
This prints
(320, 500, 3)
(375, 500, 3)
(375, 500, 3)
while if you specify greyscale,
printshape(dolphinurl,0)
printshape(stinkbugweburl,0)
printshape(stinkbugweburl,0)
it'll print
(320, 500)
(375, 500)
(375, 500)
In that sense it's up to the user to decide how they want to read in the image.
As I see it, matplotlib's imread
correctly reads in the image. If the image contains only a single channel, the resulting numpy array will be 2D. If the image contains 3 or 4 channels, the numpy array will be 3D.
Taking the dolphin image from the question you get
plt.imread("https://i.stack.imgur.com/cInHj.png").shape
> (320, 500)
Concerning the stinkbug image from the matplotlib documentation there is indeed a little problem. The image you see is a grey scale image as well,
plt.imread("https://matplotlib.org/_images/stinkbug.png").shape
> (375, 500)
However the tutorial claims it to be a 3 channel image. This is correct from the point of view of the tutorial, because it takes the image from the doc
on the github repository folder.
plt.imread("https://raw.githubusercontent.com/matplotlib/matplotlib/master/doc/_static/stinkbug.png").shape
> (375, 500, 3)
The problem is that the documentation is built through sphinx and sphinx-gallery and in addition may use some other libraries. In the course of this, the image is not copied in its raw format to the output folder. This problem has been reported already here, the reason is not yet fully tracked down.
In any case, the remaining open question is then, why does cv2.imread
give you a 3D array for a greyscale image?
From the OpenCV imread
documentation:
Second argument is a flag which specifies the way image should be read.
- cv2.IMREAD_COLOR : Loads a color image. Any transparency of image will be neglected. It is the default flag.
- cv2.IMREAD_GRAYSCALE : Loads image in grayscale mode
- cv2.IMREAD_UNCHANGED : Loads image as such including alpha channel
Note Instead of these three flags, you can simply pass integers 1, 0 or -1 respectively.
So here you need to specify yourself, which mode you want to use.
Let's verify:
import cv2
import urllib.request as req
dolphinurl ="https://i.stack.imgur.com/cInHj.png"
stinkbugweburl = "https://matplotlib.org/_images/stinkbug.png"
stinkbuggiturl = "https://raw.githubusercontent.com/matplotlib/matplotlib/master/doc/_static/stinkbug.png"
def printshape(url, **kw):
req.urlretrieve(url, "image_name.png")
im = cv2.imread("image_name.png", **kw)
print(im.shape)
printshape(dolphinurl)
printshape(stinkbugweburl)
printshape(stinkbugweburl)
This prints
(320, 500, 3)
(375, 500, 3)
(375, 500, 3)
while if you specify greyscale,
printshape(dolphinurl,0)
printshape(stinkbugweburl,0)
printshape(stinkbugweburl,0)
it'll print
(320, 500)
(375, 500)
(375, 500)
In that sense it's up to the user to decide how they want to read in the image.
answered Nov 14 '18 at 22:45
ImportanceOfBeingErnestImportanceOfBeingErnest
139k13161239
139k13161239
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.
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%2f53308792%2fmatplotlib-missing-channel-using-imread%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
dolphin.png
is a grey scale image with a single channel. Is your question how to duplicate those channels to have a grey RGB image?– ImportanceOfBeingErnest
Nov 14 '18 at 21:16
No it has three channels. Please look at the output of
imgcv.shape
. It is(320, 500, 3)
– evolved
Nov 14 '18 at 21:17
There seems to be something wrong with the
imread
command of matplotlib (or how I use it) as it results in an image with only one channel.img.shape
yields(320, 500)
– evolved
Nov 14 '18 at 21:21
So you mean
cv2.imread
is more trustworthy thanplt.imread
? I guess we can find out if you provide the original image.– ImportanceOfBeingErnest
Nov 14 '18 at 21:35
Yes, thats what I see as a result. However, I expect that
plt.imread
also results in a numpy array with three channels. Thanks for your help, I provided the original image. I also tested with the png image from the matplotlib tutorial: matplotlib.org/_images/stinkbug.png which is also missing two channels when reading withplt.imread
– evolved
Nov 14 '18 at 21:50