Input validation
If the received image is not RGB, throwing an IllegalArgumentException
without a custom message is not very friendly. Users would have to look at the code to understand what went wrong exactly.
The long chain image.getColorModel().getColorSpace().getType()
is extracted to an imageType
local variable that's only used for validation.
I would be good to move the validation to a dedicated helper method, let's say validateImageType
.
Java conventions
Member variables should be declared at the top, followed by constructors, followed by methods. Very roughly speaking. So move the declaration of threshold
higher.
Naming
As the interface name already implies the conversion to black and white,
the method name toBlackAndWhite
is redundant. I'd rename it to simply convert
.
Misc
0x000000FF
is the same as 0xFF
, so you can shorten it.