![]() ![]() In : np.array(im.getchannel(1))Īnd finally, let's look at the Blue channel. ![]() Now let's look at the Green channel, it is 0 everywhere because there is no green. Notice it has 255 at the top because it is red, and 0 at the bottom because there is no red there. ![]() First, look at the Red channel: In : im = Image.open('a.png').convert('RGB')Īrray(, Let's use IPython to look at in RGB space. You will not normally get problems with JPEG images because they are pretty much always RGB anyway. That way you will never have problems with GIF files (which are always palettised) nor with PNG files which can be palettised and can be greyscale or RGB. if you want and expect an RGB image, you should just convert to RGB on opening: im = Image.open("image.jpg").convert('RGB') You can store a grey-looking image in a P format, you just make sure all the palette entries have the R=G=B. All you do, is make the red component equal to the green component equal to the blue component (R=G=B) and it will appear grey but be stored in an inefficient RGB format that takes 3x the space it might otherwise need to. You can store a grey-looking image in an RGB format. I used the word "normally" quite a lot! Why? Because you can do abnormal things! You convert between them using the convert(mode) function, e.g. If your image is greyscale it will be L, or LA if greyscale with alpha channel. If your image is palettised it will be P, or PA if palettised with an alpha channel as well. You can tell which mode your image has by looking at: image.mode It is very compact, but only stores a greyscale, not colour. The L means that is just stores the Luminance. If you have an L mode image, that means it is a single channel image - normally interpreted as greyscale. The disadvantage is that it can only represent 256 unique colours - so you may get banding or artefacts. The advantage is that your image requires 1/3 of the space in memory and on disk. This confers both advantages and disadvantages. That means there is a palette with up to 256 different colours in it, and instead of storing 3 bytes for R, G and B for each pixel, you store 1 byte which is the index into the palette. If you have a P mode image, that means it is palettised. That normally means that each pixel takes 3 bytes of storage, one for red, one for green and one for blue. Normally, images are RGB, which means they have 3 channels, one for red, one for green and one for blue. ![]()
0 Comments
Leave a Reply. |