-
Notifications
You must be signed in to change notification settings - Fork 3
/
region_search.py
130 lines (100 loc) · 3.88 KB
/
region_search.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# -*- coding: utf-8 -*-
"""Myntra_images.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/11EJDwG5NhVU0x34MHYFwsQ1ml8nNHTez
"""
# from google.colab import drive
# drive.mount('/content/gdrive', force_remount=True)
import pandas as pd
from PIL import Image
import os
import re
import string
import numpy as np
import matplotlib.pyplot as plt
import cv2
import random
import plotly.express as px
#!pip install -q hvplot
import hvplot.pandas # custom install
from glob import glob
from urllib import request
import missingno as msno
"""**CSV Files**"""
metadata = pd.read_csv(r'C:\Users\dell\Desktop\data\images_metadata.csv')
metadata.sample(5)
metadata.sample(5)
"""**Image folders**"""
#Image Folder Paths
# north_jpg_directory = r'../../data/images/north'
north_jpg_directory = r'C:/Users/dell/Desktop/Myntra_Hackathon/static/images/north'
northeast_jpg_directory = r'C:/Users/dell/Desktop/Myntra_Hackathon/static/images/north-east'
east_jpg_directory = r'C:/Users/dell/Desktop/Myntra_Hackathon/static/images/east'
south_jpg_directory = r'C:/Users/dell/Desktop/Myntra_Hackathon/static/images/south'
western_jpg_directory = r'C:/Users/dell/Desktop/Myntra_Hackathon/static/images/western'
def getImagePaths(path):
"""
Function to Combine Directory Path with individual Image Paths
parameters: path(string) - Path of directory
returns: image_names(string) - Full Image Path
"""
image_names = []
for dirname, _, filenames in os.walk(path):
for filename in filenames:
# fullpath = os.path.join(dirname, filename)
fullpath = dirname[38:] + '/' + filename
image_names.append(fullpath)
return image_names
#Get complete image paths for all the regions
north_images_path = sorted(getImagePaths(north_jpg_directory))
northeast_images_path = sorted(getImagePaths(northeast_jpg_directory))
east_images_path = sorted(getImagePaths(east_jpg_directory))
south_images_path = sorted(getImagePaths(south_jpg_directory))
western_images_path = sorted(getImagePaths(western_jpg_directory))
south_images_path[:5]
total_images_path = north_images_path + south_images_path + east_images_path + northeast_images_path + western_images_path
def display_multiple_img(images_paths, rows, cols):
"""
Function to Display Images from Dataset.
parameters: images_path(string) - Paths of Images to be displayed
rows(int) - No. of Rows in Output
cols(int) - No. of Columns in Output
"""
figure, ax = plt.subplots(nrows=rows,ncols=cols,figsize=(40,20) )
for ind,image_path in enumerate(images_paths):
image=cv2.imread(image_path)
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
image_name = image_path.split('/')[-1]
title = metadata[metadata['images'] == image_name]['title'].tolist()[0]
try:
ax.ravel()[ind].set_title(title)
ax.ravel()[ind].imshow(image)
ax.ravel()[ind].set_axis_off()
except:
continue;
plt.tight_layout()
plt.show()
# display_multiple_img(south_images_path[:], 5, 5)
def clean_region(region):
region = re.sub('/s+', '', region.lower())
return region
def search(query_region):
# query_region = clean_region(query_region)
if query_region == 'north':
image_path = random.sample(north_images_path, 16)
elif query_region == 'north-east':
image_path = random.sample(northeast_images_path, 16)
elif query_region == 'east':
image_path = random.sample(east_images_path, 9)
elif query_region == 'south':
image_path = random.sample(south_images_path, 16)
elif query_region == 'western':
image_path = random.sample(western_images_path, 16)
# return display_multiple_img(image_path, 4, 4)
return image_path
# search('north')
# search('east')
# search('south')
import random
# random.sample(north_images_path,10)