Why is the color changed after applying ImageData?
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
I have an image square.png
as below:-
I imported the image as ImageSquare
, and then applied ImageData
to the image. When I applied Image
to convert the image back, the color is changed:-
ImageSquare = Import@StringJoin[NotebookDirectory, "square.png"]
ImageSquare2 = Image@ImageData@ImageSquare
Why is that? In fact if I checked the value of the images, I still got True
:
(ImageData@ImageSquare2) == (ImageData@ImageSquare)
Many thanks!!
image-processing color image
add a comment |Â
up vote
2
down vote
favorite
I have an image square.png
as below:-
I imported the image as ImageSquare
, and then applied ImageData
to the image. When I applied Image
to convert the image back, the color is changed:-
ImageSquare = Import@StringJoin[NotebookDirectory, "square.png"]
ImageSquare2 = Image@ImageData@ImageSquare
Why is that? In fact if I checked the value of the images, I still got True
:
(ImageData@ImageSquare2) == (ImageData@ImageSquare)
Many thanks!!
image-processing color image
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I have an image square.png
as below:-
I imported the image as ImageSquare
, and then applied ImageData
to the image. When I applied Image
to convert the image back, the color is changed:-
ImageSquare = Import@StringJoin[NotebookDirectory, "square.png"]
ImageSquare2 = Image@ImageData@ImageSquare
Why is that? In fact if I checked the value of the images, I still got True
:
(ImageData@ImageSquare2) == (ImageData@ImageSquare)
Many thanks!!
image-processing color image
I have an image square.png
as below:-
I imported the image as ImageSquare
, and then applied ImageData
to the image. When I applied Image
to convert the image back, the color is changed:-
ImageSquare = Import@StringJoin[NotebookDirectory, "square.png"]
ImageSquare2 = Image@ImageData@ImageSquare
Why is that? In fact if I checked the value of the images, I still got True
:
(ImageData@ImageSquare2) == (ImageData@ImageSquare)
Many thanks!!
image-processing color image
asked Sep 2 at 1:05


H42
1,404111
1,404111
add a comment |Â
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
2
down vote
accepted
You should specify the ColorSpace
manually:
ImageSquare2 = Image[ImageData@ImageSquare, ColorSpace -> "RGB"]
Or take it from the original image:
colorSpace = Options@ImageSquare
ImageSquare2 = Image[ImageData@ImageSquare, colorSpace]
The original approach yield:
Options@(Image@ImageData@ImageSquare)
(* ColorSpace -> Automatic, Interleaving -> True *)
Which is wrong and uses the following rule from Image
:
c1,c2,c3,… channel values rendered by equally spaced hues
add a comment |Â
up vote
2
down vote
ImageSquare2 = Image[ImageData@ImageSquare, Options@ImageSquare]
add a comment |Â
up vote
2
down vote
This happens because this PNG file has three colour channels (RGB) and an additional alpha channel (transparency).
When applying ImageData
(or ColorSeparate
) blindly, we simply get four channels as the result. But the information on how to interpret these (i.e. RGB + alpha) is lost. Re-combining them gives a generic 4-channel image, not an RGB one (see here one how it's displayed).
I suggest removing the alpha channel before using ImageData
: RemoveAlphaChannel
.
Otherwise, use ColorSpace -> "RGB"
with Image
or the second argument of ColorCombine
when recombining the channels. The fourth channel will be interpreted as an alpha channel in this case.
You can check if an image has an alpha channel like this: https://mathematica.stackexchange.com/a/157458/12
Thanks. I tried RemoveAlphaChannel as you suggested and it really works. But I don't understand why it matters. I noticed thatMinMax@(ImageData@ImageSquare)[[All, All, 4]]
is just1,1
. Besides, why is the color-at-the-left ofImageSquare
andImageSquare2
are still the same? I also tried to change the alpha-value ofImageSquare
, but that doesn't allow me to reconstruct an image that looks likeImageSquare2
.
– H42
Sep 2 at 15:51
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
You should specify the ColorSpace
manually:
ImageSquare2 = Image[ImageData@ImageSquare, ColorSpace -> "RGB"]
Or take it from the original image:
colorSpace = Options@ImageSquare
ImageSquare2 = Image[ImageData@ImageSquare, colorSpace]
The original approach yield:
Options@(Image@ImageData@ImageSquare)
(* ColorSpace -> Automatic, Interleaving -> True *)
Which is wrong and uses the following rule from Image
:
c1,c2,c3,… channel values rendered by equally spaced hues
add a comment |Â
up vote
2
down vote
accepted
You should specify the ColorSpace
manually:
ImageSquare2 = Image[ImageData@ImageSquare, ColorSpace -> "RGB"]
Or take it from the original image:
colorSpace = Options@ImageSquare
ImageSquare2 = Image[ImageData@ImageSquare, colorSpace]
The original approach yield:
Options@(Image@ImageData@ImageSquare)
(* ColorSpace -> Automatic, Interleaving -> True *)
Which is wrong and uses the following rule from Image
:
c1,c2,c3,… channel values rendered by equally spaced hues
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
You should specify the ColorSpace
manually:
ImageSquare2 = Image[ImageData@ImageSquare, ColorSpace -> "RGB"]
Or take it from the original image:
colorSpace = Options@ImageSquare
ImageSquare2 = Image[ImageData@ImageSquare, colorSpace]
The original approach yield:
Options@(Image@ImageData@ImageSquare)
(* ColorSpace -> Automatic, Interleaving -> True *)
Which is wrong and uses the following rule from Image
:
c1,c2,c3,… channel values rendered by equally spaced hues
You should specify the ColorSpace
manually:
ImageSquare2 = Image[ImageData@ImageSquare, ColorSpace -> "RGB"]
Or take it from the original image:
colorSpace = Options@ImageSquare
ImageSquare2 = Image[ImageData@ImageSquare, colorSpace]
The original approach yield:
Options@(Image@ImageData@ImageSquare)
(* ColorSpace -> Automatic, Interleaving -> True *)
Which is wrong and uses the following rule from Image
:
c1,c2,c3,… channel values rendered by equally spaced hues
answered Sep 2 at 1:15


m0nhawk
2,47811431
2,47811431
add a comment |Â
add a comment |Â
up vote
2
down vote
ImageSquare2 = Image[ImageData@ImageSquare, Options@ImageSquare]
add a comment |Â
up vote
2
down vote
ImageSquare2 = Image[ImageData@ImageSquare, Options@ImageSquare]
add a comment |Â
up vote
2
down vote
up vote
2
down vote
ImageSquare2 = Image[ImageData@ImageSquare, Options@ImageSquare]
ImageSquare2 = Image[ImageData@ImageSquare, Options@ImageSquare]
answered Sep 2 at 1:11
Michael E2
140k11191457
140k11191457
add a comment |Â
add a comment |Â
up vote
2
down vote
This happens because this PNG file has three colour channels (RGB) and an additional alpha channel (transparency).
When applying ImageData
(or ColorSeparate
) blindly, we simply get four channels as the result. But the information on how to interpret these (i.e. RGB + alpha) is lost. Re-combining them gives a generic 4-channel image, not an RGB one (see here one how it's displayed).
I suggest removing the alpha channel before using ImageData
: RemoveAlphaChannel
.
Otherwise, use ColorSpace -> "RGB"
with Image
or the second argument of ColorCombine
when recombining the channels. The fourth channel will be interpreted as an alpha channel in this case.
You can check if an image has an alpha channel like this: https://mathematica.stackexchange.com/a/157458/12
Thanks. I tried RemoveAlphaChannel as you suggested and it really works. But I don't understand why it matters. I noticed thatMinMax@(ImageData@ImageSquare)[[All, All, 4]]
is just1,1
. Besides, why is the color-at-the-left ofImageSquare
andImageSquare2
are still the same? I also tried to change the alpha-value ofImageSquare
, but that doesn't allow me to reconstruct an image that looks likeImageSquare2
.
– H42
Sep 2 at 15:51
add a comment |Â
up vote
2
down vote
This happens because this PNG file has three colour channels (RGB) and an additional alpha channel (transparency).
When applying ImageData
(or ColorSeparate
) blindly, we simply get four channels as the result. But the information on how to interpret these (i.e. RGB + alpha) is lost. Re-combining them gives a generic 4-channel image, not an RGB one (see here one how it's displayed).
I suggest removing the alpha channel before using ImageData
: RemoveAlphaChannel
.
Otherwise, use ColorSpace -> "RGB"
with Image
or the second argument of ColorCombine
when recombining the channels. The fourth channel will be interpreted as an alpha channel in this case.
You can check if an image has an alpha channel like this: https://mathematica.stackexchange.com/a/157458/12
Thanks. I tried RemoveAlphaChannel as you suggested and it really works. But I don't understand why it matters. I noticed thatMinMax@(ImageData@ImageSquare)[[All, All, 4]]
is just1,1
. Besides, why is the color-at-the-left ofImageSquare
andImageSquare2
are still the same? I also tried to change the alpha-value ofImageSquare
, but that doesn't allow me to reconstruct an image that looks likeImageSquare2
.
– H42
Sep 2 at 15:51
add a comment |Â
up vote
2
down vote
up vote
2
down vote
This happens because this PNG file has three colour channels (RGB) and an additional alpha channel (transparency).
When applying ImageData
(or ColorSeparate
) blindly, we simply get four channels as the result. But the information on how to interpret these (i.e. RGB + alpha) is lost. Re-combining them gives a generic 4-channel image, not an RGB one (see here one how it's displayed).
I suggest removing the alpha channel before using ImageData
: RemoveAlphaChannel
.
Otherwise, use ColorSpace -> "RGB"
with Image
or the second argument of ColorCombine
when recombining the channels. The fourth channel will be interpreted as an alpha channel in this case.
You can check if an image has an alpha channel like this: https://mathematica.stackexchange.com/a/157458/12
This happens because this PNG file has three colour channels (RGB) and an additional alpha channel (transparency).
When applying ImageData
(or ColorSeparate
) blindly, we simply get four channels as the result. But the information on how to interpret these (i.e. RGB + alpha) is lost. Re-combining them gives a generic 4-channel image, not an RGB one (see here one how it's displayed).
I suggest removing the alpha channel before using ImageData
: RemoveAlphaChannel
.
Otherwise, use ColorSpace -> "RGB"
with Image
or the second argument of ColorCombine
when recombining the channels. The fourth channel will be interpreted as an alpha channel in this case.
You can check if an image has an alpha channel like this: https://mathematica.stackexchange.com/a/157458/12
answered Sep 2 at 11:56
Szabolcs
152k13415896
152k13415896
Thanks. I tried RemoveAlphaChannel as you suggested and it really works. But I don't understand why it matters. I noticed thatMinMax@(ImageData@ImageSquare)[[All, All, 4]]
is just1,1
. Besides, why is the color-at-the-left ofImageSquare
andImageSquare2
are still the same? I also tried to change the alpha-value ofImageSquare
, but that doesn't allow me to reconstruct an image that looks likeImageSquare2
.
– H42
Sep 2 at 15:51
add a comment |Â
Thanks. I tried RemoveAlphaChannel as you suggested and it really works. But I don't understand why it matters. I noticed thatMinMax@(ImageData@ImageSquare)[[All, All, 4]]
is just1,1
. Besides, why is the color-at-the-left ofImageSquare
andImageSquare2
are still the same? I also tried to change the alpha-value ofImageSquare
, but that doesn't allow me to reconstruct an image that looks likeImageSquare2
.
– H42
Sep 2 at 15:51
Thanks. I tried RemoveAlphaChannel as you suggested and it really works. But I don't understand why it matters. I noticed that
MinMax@(ImageData@ImageSquare)[[All, All, 4]]
is just 1,1
. Besides, why is the color-at-the-left of ImageSquare
and ImageSquare2
are still the same? I also tried to change the alpha-value of ImageSquare
, but that doesn't allow me to reconstruct an image that looks like ImageSquare2
.– H42
Sep 2 at 15:51
Thanks. I tried RemoveAlphaChannel as you suggested and it really works. But I don't understand why it matters. I noticed that
MinMax@(ImageData@ImageSquare)[[All, All, 4]]
is just 1,1
. Besides, why is the color-at-the-left of ImageSquare
and ImageSquare2
are still the same? I also tried to change the alpha-value of ImageSquare
, but that doesn't allow me to reconstruct an image that looks like ImageSquare2
.– H42
Sep 2 at 15:51
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%2f181082%2fwhy-is-the-color-changed-after-applying-imagedata%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