2
$\begingroup$

I have an image that I'm trying to pad some transparent border. But I get error:

"The specified padding value is not compatible with a 3-channel image."

data = Table[{45, 45, 45}, {20}, {25}];
p = Image[RawArray["Byte", data], "Byte", Rule[ColorSpace, Automatic],
    Rule[Interleaving, True]];

ImagePad[p, 10, Transparent]

What does this error mean and how to solve it?

Update

If test on the documentation figure, padding transparent works even it has a Automatic color space:

enter image description here

$\endgroup$
  • $\begingroup$ Is there a reason, why you are using Automatic for the ColorSpace? $\endgroup$ – Karsten 7. Sep 6 '14 at 17:02
3
$\begingroup$

You have to convert Transparent into, e.g., the RGB color space:

ImagePad[p, 10, ColorConvert[Transparent, "RGB"]]

This is due to the fact, that Transparent is GrayLevel[0,0] and is incompatible with the ImageColorSpace of your image p (Automatic, which means that no color space is specified).
You can also convert your image into a specific color space, e.g.

ImagePad[ColorConvert[p, "Grayscale"], 10, Transparent]
ImagePad[ColorConvert[p, "RGB"], 10, Transparent]
$\endgroup$
  • $\begingroup$ Thanks for the asnwer, it's very helpful. I didn't know that the problem was from color space. TheAutomatic comes from importing a video. $\endgroup$ – xslittlegrass Sep 6 '14 at 18:00
  • $\begingroup$ It' s strange that a figure in the documentation also has the color space goes to Automatic, but padding transparent works.See my update. Do you know why? $\endgroup$ – xslittlegrass Sep 8 '14 at 23:32
  • $\begingroup$ @xslittlegrass Its Automatic is different, as it has only one channel (use ImageChannels@p to check) compared to the 3 channels of your original p. $\endgroup$ – Karsten 7. Sep 9 '14 at 16:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.