0

So, I'm trying to create a image fill it up with colors and then display it for debugging. I've created the image with pillow, set it to black or, (0,0,0) in rgb, I cycle through and fill up the image with actual color, etc. But then I get an error for some attribute I don't know how to fill up in python.

import cv2
import tkinter as tk
import copy
from PIL import Image
from tkinter import filedialog


colorwheel = Image.new('RGB', (1, 255*7), color='black')
     colorwheel = colorwheel.load()
     colorwheel[0,1]=(255,255,0)
     colorwheel[0,2] = (255, 255, 0)
     r=255
     g=255
     b=0
     #keep value of green, add take away red
     for i in range( 255):
          colorwheel[0, i] = (255-1, 255, 0)


     #go to blue take away green
     for i in range( 255):
          colorwheel[0,255*2 + i] = (0, 255-i,0+1)

     #go to purple 128 keep blue, add red to 128
     for i in range (255):
          colorwheel[0, 255*3 + i] = (int(i/2), 0, 255)

     #go to red
     for i in range( 255):
          colorwheel[0,255*4 + i]=(int(i/2),0,255-i)

     #go to orange
     for i in range(255):
          colorwheel[0, 255 * 5 + i] = (128, int(i / 2), 0) #keep red 128


     for i in range(255):
          colorwheel[0, 255 * 6 + i] =(128,int(128+i/2),0)



     colorwheel.resize((50,255*7))
     cv2.imshow('image', colorwheel)

It should have everything it needs to resize and display the image, but I get this.

File "C:/Users/misterE/PycharmProjects/frame2cc/base contraster", line 64, in <module>
    colorwheel.resize((50,255*7))
AttributeError: 'PixelAccess' object has no attribute 'resize'
ladygremlin
  • 452
  • 3
  • 14

2 Answers2

0

It looks like PixelAccess doesn't have the function resize(), according to the Pillow docs.

If you're looking to resize an image, this post about resizing an image using PIL might be useful!

ladygremlin
  • 452
  • 3
  • 14
0

Try:-

import cv2
import tkinter as tk
import copy
from PIL import Image
from tkinter import filedialog


colorwheel1 = Image.new('RGB', (1, 255*7), color='black')
colorwheel = colorwheel1.load()
colorwheel[0,1]=(255,255,0)
colorwheel[0,2] = (255, 255, 0)
r=255
g=255
b=0
#keep value of green, add take away red
for i in range( 255):
     colorwheel[0, i] = (255-1, 255, 0)

 #go to blue take away green
for i in range( 255):
     colorwheel[0,255*2 + i] = (0, 255-i,0+1)

 #go to purple 128 keep blue, add red to 128
for i in range (255):
     colorwheel[0, 255*3 + i] = (int(i/2), 0, 255)

#go to red
for i in range( 255):
     colorwheel[0,255*4 + i]=(int(i/2),0,255-i)

#go to orange
for i in range(255):
     colorwheel[0, 255 * 5 + i] = (128, int(i / 2), 0) #keep red 128


for i in range(255):
     colorwheel[0, 255 * 6 + i] =(128,int(128+i/2),0)



colorwheel1.resize((50,255*7))
colorwheel1.show()

OUTPUT IMAGE:-

The reason for your error was, that you were trying to use Image object command (Image.resize()) on a PixelAccess element. Which caused this error. For fixing that, we just changed the name of the original Image object to colorwheel1 so that we can further use this object for resizing.

P.S.:- I used Image.show() in the end for displaying the image rather then cv2.imshow().

Vasu Deo.S
  • 1,820
  • 1
  • 11
  • 23