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.
import numpy as np
from scipy import stats
10 RGB images. Generates 10 average images, median images, and mode images, respectively.
imgs.shape # (10, 128, 128, 3)
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)
img_median = np.median(imgs, axis=0)
img_median.shape # (128, 128, 3)
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