Skip to content

Commit

Permalink
new function, linted'
Browse files Browse the repository at this point in the history
  • Loading branch information
drcandacemakedamoore committed May 21, 2021
1 parent 2323b8c commit f35d414
Showing 1 changed file with 30 additions and 20 deletions.
50 changes: 30 additions & 20 deletions cleanX.py
Original file line number Diff line number Diff line change
Expand Up @@ -1407,53 +1407,63 @@ def set_image_variability(set_of_images):
return final_diff


def avg_image_maker_by_label(master_df,dataframe_image_column, dataframe_label_column, image_folder):
def avg_image_maker_by_label(
master_df,
dataframe_image_column,
dataframe_label_column,
image_folder,
):

"""
:param master_df: Dataframe with image location and labels
:type master_df: Dataframe
:param dataframe_image_column: name of dataframe column with image location string
This function sorts images by labels and makes an average image per label.
If images are all the same size subtracting one from the other should
reveal salient differences.
:param master_df: Dataframe with image location and labels
:type master_df: Dataframe
:param dataframe_image_column: name of dataframe column with image location
string
:type dataframe_image_column:string
:param dataframe_label_column: name of dataframe column with label string
:type dataframe_label_column:string
:param image_folder: name of folder where images are
:type image_folder:string
:return: list of titled average images per label
:rtype: list
"""
final_img_list = []
final_name_list = []
set_of_labels = master_df[dataframe_label_column].unique()
for name in set_of_labels:
for name in set_of_labels:
sets_of_images = []

list_h = []
list_w = []

for example in master_df[dataframe_image_column][master_df[dataframe_label_column] == name]:
example = cv2.imread(image_folder+example, cv2.IMREAD_GRAYSCALE)
ht= example.shape[0]
wt= example.shape[1]
list_h.append(ht)

for example in master_df[
dataframe_image_column][master_df[
dataframe_label_column]
== name]:
example = cv2.imread(image_folder + example, cv2.IMREAD_GRAYSCALE)
ht = example.shape[0]
wt = example.shape[1]
list_h.append(ht)
list_w.append(wt)


h = int(sum(list_h)/len(list_h))
h = int(sum(list_h)/len(list_h))
w = int(sum(list_w)/len(list_w))
canvas = np.zeros((h, w))
for example in master_df[dataframe_image_column]:
example = cv2.imread(image_folder+example, cv2.IMREAD_GRAYSCALE)
for example in master_df[dataframe_image_column]:
example = cv2.imread(image_folder+example, cv2.IMREAD_GRAYSCALE)
example_small = cv2.resize(example, (w, h))
canvas += np.array(example_small)
final_avg = canvas / len(dataframe_image_column)
final_avg = canvas / len(dataframe_image_column)
final_img_list.append(final_avg)
final_name_list.append(name)
stick = pd.DataFrame(final_name_list)
stick_data = {'name': final_name_list, 'images': final_img_list}

df = pd.DataFrame(data=stick_data)


stick['images'] = final_img_list
return df

0 comments on commit f35d414

Please sign in to comment.