'How to perform PCA and UMAP dimensionality reduction with multiple images together

I have implemented PCA and UMAP dimensionality reduction for a single hyperspectral image. I didn't any problem. But now I have multiple hyperspectral images(more than 200). I would perform PCA and UMAP dimensionality reduction on datasets that contain hyperspectral multiple images. Please find the dataset shape look like - Firstly I have extracted the data frame from a single image -

import pandas as pd
import numpy as np

def extract_pixels(datacube, labelmap):
  q = datacube.reshape(-1, datacube.shape[2])
  df = pd.DataFrame(data = q)
  df = pd.concat([df, pd.DataFrame(data = labelmap.ravel())], axis=1)
  df.columns= [f'band{i}' for i in range(1, 1+datacube.shape[2])]+['class']
  df.to_csv('Dataset.csv')
  return df
  
df = extract_pixels(datacube, labelmap)

Then I apply PCA to algorithm to above df

from sklearn.decomposition import PCA

pca = PCA(n_components = 15)

principalComponents = pca.fit_transform(df.iloc[:, :-1].values)

My question is how do I apply PCA and UMAP to all images together. Practically It is not efficient to apply PCA and UMAP to all 200 images.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source