Created
August 12, 2020 16:23
-
-
Save bala-codes/842f3593881d4e6ce6c0e944e421fb9d to your computer and use it in GitHub Desktop.
BCCD Preprocess
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
img_width = 640 | |
img_height = 480 | |
def width(df): | |
return int(df.xmax - df.xmin) | |
def height(df): | |
return int(df.ymax - df.ymin) | |
def x_center(df): | |
return int(df.xmin + (df.width/2)) | |
def y_center(df): | |
return int(df.ymin + (df.height/2)) | |
def w_norm(df): | |
return df/img_width | |
def h_norm(df): | |
return df/img_height | |
df = pd.read_csv('/content/blood_cell_detection.csv') | |
le = preprocessing.LabelEncoder() | |
le.fit(df['cell_type']) | |
print(le.classes_) | |
labels = le.transform(df['cell_type']) | |
df['labels'] = labels | |
df['width'] = df.apply(width, axis=1) | |
df['height'] = df.apply(height, axis=1) | |
df['x_center'] = df.apply(x_center, axis=1) | |
df['y_center'] = df.apply(y_center, axis=1) | |
df['x_center_norm'] = df['x_center'].apply(w_norm) | |
df['width_norm'] = df['width'].apply(w_norm) | |
df['y_center_norm'] = df['y_center'].apply(h_norm) | |
df['height_norm'] = df['height'].apply(h_norm) | |
df.head(30) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment