[PYTHON] Draw multiple photos in a graph from multiple folders

Well, as the title says ...

When I tried to compare photos A and B, I noticed that "Oh, I divided them into folders." I steadily looked at the photos from one folder and divided them into folders ... I tried it as a trigger. By the way, I was trapped when I processed the image, so I will go with it.

It wasn't difficult at all

"Isn't it better to increase the chord atmosphere?" I was able to do it if I proceeded with a feeling like that. A man who does not study as usual.

dog_and_cat.py



#I tried to fully merge Jupyter Notebook cells

import os
import glob
import matplotlib.pyplot as plt
from PIL import Image
from google.colab import drive

# GoogleDrive_Mount
drive.mount('/content/drive')

#Specify the data storage folder
input_dir="/content/drive/My Drive/Colab Notebooks/test/Photos"
dirs = glob.glob(input_dir + '/*.jpg')
input_dir2="/content/drive/My Drive/Colab Notebooks/test/Photos2"
dirs2 = glob.glob(input_dir2 + '/*.jpg')

#Check if you can refer
print(dirs)
print(dirs2)

#Add the length of the list and check the number of displayed sheets
hs = len(dirs)+len(dirs2)
print(hs)

#Display settings
col=5
row=hs/col
cols=col*3
rows=row*4
dpis = 100

#Image display size and resolution
fig = plt.figure(figsize=(cols,rows),dpi=dpis)

#** Third designation
pi=1

#Image display
for img,img2 in zip(dirs,dirs2):
#1st stage
  plot_num = pi
  ax=fig.add_subplot(row, col, plot_num)
  ac=os.path.basename(img)
  ax.set_title(ac)
  img = Image.open(img)
  plt.imshow(img, cmap='gray')
#2nd stage
  plot_num2 = pi+5
  bx=fig.add_subplot(row, col, plot_num2)
  bc=os.path.basename(img2)
  bx.set_title(bc)
  img2 = Image.open(img2)
  plt.imshow(img2, cmap='gray')
  pi = pi+1

Output result

test110401.jpg

Well, it's cute. But the sizes are different.

Try to match the size

Under "img = Image.open (img)" and "img2 = Image.open (img2)" Try to put each (for the time being, put 200 in the number)

img = img.resize((200, 200))  
img2 = img2.resize((200, 200)) 
test110402.jpg

Everyone was safe. good for you.

Try grayscale too. that? trap?

Expect graying by adding the following to the above code

img = img.convert("L")
img2 = img2.convert("L")
test110403.jpg

Something different from the image ... It seems that I have to do this further if I think. Unconscious. (There was a place where I wrote something that could be done with just this.)

plt.imshow(img, cmap='gray')
plt.imshow(img2, cmap='gray')
test110404.jpg

Towards deep learning

In the future, we have to output features and extract similar images. It seems difficult, but it's really fun to be able to learn again.

Teka, I noticed that there is a little "A" in the image Dassa wwww I won't fix it, but w

Recommended Posts

Draw multiple photos in a graph from multiple folders
Draw a graph of a quadratic function in Python
Draw a graph with Japanese labels in Jupyter
Draw a graph with matplotlib from a csv file
Draw a "breast curved surface" in a 3D graph (2)
Draw graph in python
Draw a graph in Julia ... I tried a little analysis
Draw a graph with NetworkX
Draw a heart in Python
Draw a graph with networkx
How to slice a block multiple array from a multiple array in Python
Draw a graph with Julia + PyQtGraph (2)
Draw a scatterplot matrix in python
Draw a graph with Julia + PyQtGraph (1)
Draw retention rate graph in Matplotlib
Draw a graph with pandas + XlsxWriter
Draw a CNN diagram in Python
Draw a graph with PySimple GUI
How to draw a graph using Matplotlib
(Matplotlib) I want to draw a graph with a size specified in pixels
Draw a heart in Ruby with PyCall
Draw a heart in Python Part 2 (SymPy)
How to draw a bar graph that summarizes multiple series with matplotlib
Draw a tree in Python 3 using graphviz
Generate a class from a string in Python
Simply draw a graph by specifying a file
Draw a graph with PyQtGraph Part 1-Drawing
I got the date from the pub rice in Kagawa and drew a graph
How to draw a 2-axis graph with pyplot
How to draw a 3D graph before optimization
Create a standard normal distribution graph in Python
Draw a graph with PyQtGraph Part 3-PlotWidget settings
Draw a graph by processing with Pandas groupby
[Python] Draw a directed graph with Dash Cytoscape
From file to graph drawing in Python. Elementary elementary
Draw a graph with PyQtGraph Part 4-PlotItem settings
Call a Python script from Embedded Python in C ++ / C ++
Create a datetime object from a string in Python (Python 3.3)
Draw a graph with PyQtGraph Part 6-Displaying a legend
[Python] How to draw a histogram in Matplotlib
Draw a weakness graph in Python and save it in various formats (Raspberry Pi, macOS)
[Python] Representing the number of complaints from life insurance companies in a bar graph
Draw a graph with PyQtGraph Part 5-Increase the Y-axis
[Python] How to draw a line graph with Matplotlib
Receive dictionary data from a Python program in AppleScript
Until drawing a 3D graph in Python on windows10
To receive multiple return values ​​from a function executed using parallel processing (Pool) in Python