[Python] Takes representative values ​​of multiple images [Numpy]

Purpose

Generate an image using the representative value of each pixel of multiple images. For example, I want to make an average image of 10 images.

Preparation

Library Import

import numpy as np
from scipy import stats

image

10 RGB images. Generates 10 average images, median images, and mode images, respectively.

imgs.shape    # (10, 128, 128, 3)

average

You can check the axis you want to set as axis with x.shape.

img_mean = np.mean(imgs, axis=0)
img_mean.shape    # (128, 128, 3)

Median

img_median = np.median(imgs, axis=0)
img_median.shape    # (128, 128, 3)

Mode

Scipy because numpy doesn't have a library to find the mode. There may be other good ways.

#Since there are two return values, mode and count, only mode is picked up.
img_mode = stats.mode(imgs, axis=0)[0]

#Match shape with other representative image
img_mode.shape    # (1, 128, 128, 3)
img_mode = img_mode.reshape(128, 128, 3)

img_mode.shape    # (128, 128, 3)

Recommended Posts

[Python] Takes representative values ​​of multiple images [Numpy]
Python --Check type of values
Optimal placement of multiple images
Install multiple versions of Python
Faster loading of Python images
[ev3dev × Python] Control of multiple motors
Pixel manipulation of images in Python
Post multiple Twitter images with python
Animate multiple still images with Python
[Python] Various combinations of strings and values
Get rid of DICOM images in Python
[Python] (Line) Extract values from graph images
Python numpy ignores very small values ​​and displays
Examine any combination of values in multiple arrays
Use multiple versions of python environment with pyenv
1. Statistics learned with Python 1-2. Calculation of various statistics (Numpy)
Getting rid of DICOM images in Python Part 2
[Python numpy] Dynamically specify the index of the array
Anonymous upload of images using Imgur API (using Python)
[Data science memorandum] Handling of missing values ​​[python]
Introduction of Python
Notes on exchanging and multiple assignment of Python variable values ​​learned in quiz format
Python: Tips-Swap values
Basics of Python ①
Basics of python ①
#Python basics (#Numpy 1/2)
Copy of python
#Python basics (#Numpy 2/2)
Python #Numpy basics
[Python] Numpy memo
Introduction of Python
[Python] Chapter 02-06 <Supplement> Basics of Python programs (handling of numerical values)
(Python) Treat integer values as a set of flags
Try projective transformation of images using OpenCV with Python
How to display multiple images of galaxies in tiles
Display a histogram of image brightness values in python
[Python] Types of statistical values (features) and calculation methods
I tried "morphology conversion" of images with Python + OpenCV