Skip to content
Snippets Groups Projects
Commit 2da9f66a authored by goldaan's avatar goldaan
Browse files

test

parents
No related branches found
No related tags found
No related merge requests found
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">
<option name="PROJECT_TEST_RUNNER" value="Unittests" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.6.0rc2 (A:\Users\Antje\AppData\Local\Programs\Python\Python36\python.exe)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/PTTTest.iml" filepath="$PROJECT_DIR$/.idea/PTTTest.iml" />
</modules>
</component>
</project>
\ No newline at end of file
This diff is collapsed.
PTTTest/IMG_3119.JPG

256 KiB

PTTTest/IMG_3162.JPG

86.2 KiB

PTTTest/IMG_3217.JPG

181 KiB

PTTTest/IMG_3512.JPG

401 KiB

from PIL import Image
import numpy
#import requests #great lib for connecting with a REST interface
def image_test():
list=["IMG_3119.JPG","IMG_3162.JPG","IMG_3217.JPG","IMG_3512.JPG","test.jpg","test2.jpg","wagen.jpg"]
for item in list:
test_mean(item)
def test_mean(img):
im = Image.open(img)
width, height = im.size
box_list = [] #later contains tuples for easier using of crop-function; used for getting 100x100 areas of the image
mean_list = [] #later comtains the tuples of the mean color of the 100x100 areas
counter_list = [] # later comtains the tuples of the mean color of the 100x100 areas
#generates tuples for the box_list;
for x in range(int(width/100)):
for y in range(int(height/100)):
box=(x*100,y*100,(x+1)*100,(y+1)*100)
box_list.append(box)
for item in box_list:
mean_list.append(box_mean(im.crop(item))) #generates the mean_list
counter_list=rgb_count(mean_list)
max=rgb_max3(counter_list)
mean=box_mean(im)
#print(box_list)
#print(mean_list)
#print(counter_list)
print(im.getdata())
print(max)
max_list=[max[0][0],max[1][0],max[2][0]]
show_color(max_list)
#print(mean)
#Helpfunction; returns the mean rgb valur of a given image (area)
def box_mean(img_region):
r, g, b = img_region.split() #split in r,g, and b channel
#mean computing for each channel
meanvalr = int(numpy.mean(r))
meanvalg = int(numpy.mean(g))
meanvalb = int(numpy.mean(b))
#return as tuple
return ((meanvalr,meanvalg,meanvalb))
def rgb_count(rgbList):
count_list=[]
first=rgbList.pop()
#first_element=[first,1] #form of the list elements: [(r,g,b),count]
count_list.append([first,1])
for item in rgbList:
found = False
#top=rgbList.pop()
for element in count_list:
if alike(item,element[0],25):#45 seems to be a good value
element[1] += 1
found=True
break
if not found:
count_list.append([item,1])
print(item)
return count_list
# helpfunktion for better code reading; checks, if the rgb color t1 nearly t2. var is for the accepted difference; returns bool
def alike(t1,t2,var):
bool0 = (t1[0] >= ((t2[0]) - var)) and (t1[0] <= ((t2[0]) + var))
bool1 = (t1[1] >= ((t2[1]) - var)) and (t1[1] <= ((t2[1]) + var))
bool2 = (t1[2] >= ((t2[2]) - var)) and (t1[2] <= ((t2[2]) + var))
return(bool0 & bool1 & bool2)
def rgb_max3(list):
max_list=[]
for i in range(3):
max = list[0]
for item in list:
if item[1]>max[1]:
max=item
max_list.append(max)
list.remove(max)
return max_list
def show_color(max_list):
print("maxlist=",max_list)
im=Image.open("test.jpg")
pic=im.crop((0,0,600,200))
pixels=pic.load()
for x in range(600):
for y in range(200):
if x<200:
pixels[x,y]=max_list[0]
if x>=200 and x<400:
pixels[x, y] = max_list[1]
if(x >= 400):
pixels[x,y]=max_list[2]
pic.show()
#_________________________not needed anymore______________________________________________________________
def image_boxing(img):
im=Image.open(img)
width, height = im.size # image size
mean_list = [] # saves the mean rgb value of each area
box=()
x=0
y=0
#let the boxing begin (area of 50x50 pixels)
while (x<width):#wie rum läuft was?
while (y<height): #brechnung der einzelnen felder
if(x+50>=width&y+50>height):#fall für letztes feld
img_region = im.crop((x, y, (width - 1),(height-1)))
r, g, b = img_region.split()
meanvalr = int(numpy.mean(r))
meanvalg = int(numpy.mean(g))
meanvalb = int(numpy.mean(b))
addtuple=(meanvalr,meanvalg,meanvalb)
mean_list.append(addtuple)
break
if(x+50>=width):
img_region=im.crop((x,y,(width-1),(y+50)))
r, g, b = img_region.split()
meanvalr = int(numpy.mean(r))
meanvalg = int(numpy.mean(g))
meanvalb = int(numpy.mean(b))
addtuple = (meanvalr, meanvalg, meanvalb)
mean_list.append(addtuple)
y=y+50
if(y+50>=height):
img_region = im.crop((x, y, (x+50), (height-1)))
r, g, b = img_region.split()
meanvalr = int(numpy.mean(r))
meanvalg = int(numpy.mean(g))
meanvalb = int(numpy.mean(b))
addtuple = (meanvalr, meanvalg, meanvalb)
mean_list.append(addtuple)
x=x+50
else:
img_region = im.crop((x, y, (x+50), (y + 50)))
r, g, b = img_region.split()
meanvalr = int(numpy.mean(r))
meanvalg = int(numpy.mean(g))
meanvalb = int(numpy.mean(b))
addtuple = (meanvalr, meanvalg, meanvalb)
mean_list.append(addtuple)
y=y+50
print(mean_list)
print("should be:"+(width/50)*(height/50))
print("is:"+mean_list.count())
def picture_to_colors():
im = Image.open("test.jpg")
pixels = list(im.getdata()) #gets the rgb values from all pixels of the image and puts them in a list
return pixels
def show_Image(im):
test=Image.open(im)
test.show()
def test_show():
img=Image.open("test.jpg")#loads image
width,height=img.size
print((width,height))
box = (0, 0, 50, 50) #tupel, das angibt, von wo bis wo die pixel genommen werden sollen
img_region = img.crop(box) #takes the defined area
#pixels = list(img_region.getdata()) # get pixels of the area
#print(pixels)
r,g,b=img_region.split()
meanvalr = int(numpy.mean(r))
meanvalg = int(numpy.mean(g))
meanvalb = int(numpy.mean(b))
img_region.show()
# pixels=list(img_region.getdata()) #get pixels of the area
# meanval=numpy.mean(pixels)
# print(pixels)
# print(meanval)
print((meanvalr, meanvalg, meanvalb))
#elemente zu sortieren könnte sinnvoll sein
def colorcounter(rgbList):
counterList=[] #in this list all rgb values of the image get saved with their number of appearance in the image
for i in rgbList:
new_element=[i,rgbList.count(i)]
if new_element not in counterList:
counterList.append(new_element)#rgb values get in the list. "count" counts the number of appearance
return counterList
#idee: nach größe des vorkommens sortieren. ersten 3 elemente der Liste ausgeben lassen.
#def get_the_most(counterList):
# for i in counterList:
PTTTest/test.jpg

7.01 MiB

PTTTest/test2.jpg

3.73 MiB

PTTTest/wagen.jpg

1.91 MiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment