-
Notifications
You must be signed in to change notification settings - Fork 28.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SPARK-23205][ML] Update ImageSchema.readImages to correctly set alpha values for four-channel images #20389
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, LGTM.
Test build #86607 has finished for PR 20389 at commit
|
Test build #86609 has finished for PR 20389 at commit
|
Thanks for the reviews @srowen, @dongjoon-hyun! Would it make sense to merge this before Spark 2.3 is released & if so would one of you be able to do so? |
It's minor, though that cuts two ways - low risk to merge, but not critical. I think that's a moderately important issue for this module and a clean fix so I'd put it in branch 2.3 |
@@ -169,8 +169,7 @@ object ImageSchema { | |||
var offset = 0 | |||
for (h <- 0 until height) { | |||
for (w <- 0 until width) { | |||
val color = new Color(img.getRGB(w, h)) | |||
|
|||
val color = new Color(img.getRGB(w, h), nChannels == 4) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't directly use hasAlpha
?
@@ -169,8 +169,7 @@ object ImageSchema { | |||
var offset = 0 | |||
for (h <- 0 until height) { | |||
for (w <- 0 until width) { | |||
val color = new Color(img.getRGB(w, h)) | |||
|
|||
val color = new Color(img.getRGB(w, h), nChannels == 4) | |||
decoded(offset) = color.getBlue.toByte | |||
decoded(offset + 1) = color.getGreen.toByte | |||
decoded(offset + 2) = color.getRed.toByte |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At line 177,
if (nChannels == 4) {
decoded(offset + 3) = color.getAlpha.toByte
}
We can directly use hasAlpha
too, instead of indirectly comparing nChannels
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! Minor comments.
Test build #86645 has finished for PR 20389 at commit
|
…a values for four-channel images ## What changes were proposed in this pull request? When parsing raw image data in ImageSchema.decode(), we use a [java.awt.Color](https://docs.oracle.com/javase/7/docs/api/java/awt/Color.html#Color(int)) constructor that sets alpha = 255, even for four-channel images (which may have different alpha values). This PR fixes this issue & adds a unit test to verify correctness of reading four-channel images. ## How was this patch tested? Updates an existing unit test ("readImages pixel values test" in `ImageSchemaSuite`) to also verify correctness when reading a four-channel image. Author: Sid Murching <sid.murching@databricks.com> Closes #20389 from smurching/image-schema-bugfix. (cherry picked from commit 7bd46d9) Signed-off-by: Sean Owen <sowen@cloudera.com>
Merged to master/2.3 |
What changes were proposed in this pull request?
When parsing raw image data in ImageSchema.decode(), we use a java.awt.Color constructor that sets alpha = 255, even for four-channel images (which may have different alpha values). This PR fixes this issue & adds a unit test to verify correctness of reading four-channel images.
How was this patch tested?
Updates an existing unit test ("readImages pixel values test" in
ImageSchemaSuite
) to also verify correctness when reading a four-channel image.