예제 #1
0
def task2(file_name): # I defined task2() function.
	data = pickle.load (open('image_matrix','rb')) # to open data file, i used pickle.load.

	red_values = []
	for x in data:
		for y in x:
			red_values.append(y[0])

	green_values = []
	for x in data:
		for y in x:
			green_values.append(y[1])
	blue_values = []
	for x in data:
		for y in x:
			blue_values.append(y[2])

	"""In order to get red, green and blue values seperated. i made seperated list of R,G,B Values.
	and i put those value lists to final list"""

	final = [red_values, green_values, blue_values]

	return final

	hp.hist_plotter(final) #To use helper module i used hp.hist_plotter.
예제 #2
0
                    if firstImage[x][y][z] > 191 and firstImage[x][y][z] <= 255:
                        blueBin[3]+=1

                        #The if statements then filter and adds to the correct intensity as a counter

    masterList = [redBin,greenBin,blueBin]
    #the lists are then placed on a master list

    print(masterList)
    # if there is a known amount already then printing the master list will verify that

    #masterList is then returned for usage by the histogram function
    return masterList

data = open('image_matrix','rb')
#To use the data the file containing must be opened with the rb reading attribute
newData = pickle.load(data)
#The data is then dezerialized and passed to a new variable for usage
data.close()
#once the data is stored on the new variable the file is close

first = len(newData)
#to use the function the number of lists must be first known
second = len(newData[0])
#the number of tuples per list must also be known

#task2(first,second,newData)
hp.hist_plotter(task2(first,second,newData))
#The function to make the histograms is then used with the function as part of its parametes
예제 #3
0
	data = pickle.load (open('image_matrix','rb')) # to open data file, i used pickle.load.

	red_values = []
	for x in data:
		for y in x:
			red_values.append(y[0])

	green_values = []
	for x in data:
		for y in x:
			green_values.append(y[1])
	blue_values = []
	for x in data:
		for y in x:
			blue_values.append(y[2])

	"""In order to get red, green and blue values seperated. i made seperated list of R,G,B Values.
	and i put those value lists to final list"""

	final = [red_values, green_values, blue_values]

	return final

	hp.hist_plotter(final) #To use helper module i used hp.hist_plotter.


hp.hist_plotter(task2("image_matrix")) 
# To execute the task2. and i got the results of histograms.


예제 #4
0
#get image with pickle
image = pickle.load(open("image_matrix", "rb"))

#make three empty lists for r,g,b values
red = []
green = []
blue = []


#use nested loop to append all data from image into r,g,b lists
def histogram(image):
    for val in image:
        for i in val:
            #append all values of data into r,g,b lists, red[0], green[1], blue[2]
            red.append(i[0])
            green.append(i[1])
            blue.append(i[2])
    #after we append everything into three seperate lists we sort each one
    red.sort()
    green.sort()
    blue.sort()
    #stores all sorted r,g,b lists in one big list called myList
    myList = [red, green, blue]
    #return myList with all three r,g,b lists in one big list
    return myList


#call the hw1_hist_plotter with myList as a paramater which holds the r,g,b lists
hp.hist_plotter(histogram(image))
예제 #5
0
    if bins[1][0] <= x <= bins[1][1]:
        greenlist.append(greenlist[0][1] + 1)

green2 = greenlist.count(1)

greenlist = [(0, 0, 0, 0)]
for x in green_values:
    if bins[2][0] <= x <= bins[2][1]:
        greenlist.append(greenlist[0][2] + 1)

green3 = greenlist.count(1)

greenlist = [(0, 0, 0, 0)]
for x in green_values:
    if bins[3][0] <= x <= bins[3][1]:
        greenlist.append(greenlist[0][3] + 1)

green4 = greenlist.count(1)

greenfinal = [green1, green2, green3, green4]

rgbvalue = [redfinal, greenfinal, bluefinal]

task2 = [red_values, green_values, blue_values]

final = ['Red', 'Green', 'Blue']

final = dict(zip(final, rgbvalue))

hp.hist_plotter(task2)
예제 #6
0
import hw1_hist_plotter as hp

# Using pickle module, load the binary data file 'homework_1_image_matrix.dat'
import pickle
with open("image_matrix", "rb") as f:
    matrix = pickle.load(f)

# Separate the red values from the data and put them into red_val list
red_val = []
for x in matrix:
    for y in x:
        red_val.append(y[0])

# Separate the green values from the data and put them into green_val list
green_val = []
for x in matrix:
    for y in x:
        green_val.append(y[1])

# Separate the blue values from the data and put them into blue_val list
blue_val = []
for x in matrix:
    for y in x:
        blue_val.append(y[2])

# Make a list of three separated lists of red, green, and blue values
list = [red_val, green_val, blue_val]

# Using 'hist_plotter' function in hp, create three SVG files of R,G,B histograms
hp.hist_plotter(list)
예제 #7
0
	for x in range(len(my_file)):
		for y in range(len(my_file[x])):
			redlist.append(my_file[x][y][0])
			greenlist.append(my_file[x][y][1])
			bluelist.append(my_file[x][y][2])
	list.append(redlist)
	list.append(greenlist)
	list.append(bluelist)
	return list

listHist = le.histogram()

with open(str(listHist), 'rb') as pickle_file:
	my_file = pickle.load(pickle_file)

hp.hist_plotter(task2(my_file))


"""def entropy(signal):
    '''
    function returns entropy of a signal
    signal must be a 1-D numpy array
    '''
    lensig=signal.size
    symset=list(set(signal))
    numsym=len(symset)
    propab=[np.size(signal[signal==i])/(1.0*lensig) for i in symset]
    ent=np.sum([p*np.log2(1.0/p) for p in propab])
    return ent
"""
#le.show()