Skip to content

Instantly share code, notes, and snippets.

@therealnaveenkamal
Created July 20, 2021 06:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save therealnaveenkamal/b95f99f1ec429c1544f1a8f2c7c9895b to your computer and use it in GitHub Desktop.
Save therealnaveenkamal/b95f99f1ec429c1544f1a8f2c7c9895b to your computer and use it in GitHub Desktop.
This code takes in a random sample image, plots a histplot and analyzes the pixel intensities
num = np.random.randint(trainset.shape[0])
sample = plt.imread(os.path.join(img_dir,trainset.iloc[[num]]["Image"].values[0]))
plt.figure(figsize=(15, 15))
plt.title(dataframe[dataframe["Image Index"] == trainset.iloc[[num]]["Image"].values[0]].values[0][1])
plt.imshow(sample, cmap = 'gray')
plt.colorbar()
trainset.iloc[[num]]
print("Maximum Pixel Value: ", sample.max())
print("Minimum Pixel Value: ", sample.min())
print(f"Image dimension: {sample.shape[0]} x {sample.shape[1]} ")
fig, ax = plt.subplots(figsize=(25, 10))
plt.xlabel("Pixel Values")
print("Mean - Pixel Value: ", sample.mean())
print("Std Deviation Pixel Value: ", sample.std())
sns.histplot(sample.ravel(), ax = ax, kde = True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment