複数の画像データの標準化

前提

ある論文の再現をしようとしていますが、画像の標準化のところで苦戦しています。
使用言語はpythonです。
目標としては以下の図のような標準化をしたいと考えています。
(a)が元画像、(b)が標準化後です。
イメージ説明

論文中のデータセットは以下のようになっています。
一つのインデックスには画像のサイズである60×160の計9600次元が特徴量として入力されています。
画像は2880枚あり各画像がインデックスを担っています。
応答値は画像と関係ないので省きます。
イメージ説明

標準化は以下の画像に示した式に従い行っているそうです。
なお、iは番号(画像の番号)、jは列番号(特徴量の番号)を示しており、μは平均、σは標準偏差を示しているそうです。
イメージ説明

実現したいこと

前提で提示したような標準化画像が得たい。
現在は前段階として画像枚数を5枚のデータセットで実現しようとしている。
ライブラリーインポート後に画像の読み込み、サイズの変更などをしている。
イメージ説明

その後データセットを作成した。イメージ説明

データセット作成後に各値を変数に代入した。
イメージ説明

代入後にいよいよ標準化したらエラーが出てきた。
標準化のコードは以下のとおりである。
イメージ説明

発生している問題・エラーメッセージ

SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy df_copy[index_count][colum_count]=(df[index_count][colum_count]-df_mean[colum_count])/df_std[colum_count] --------------------------------------------------------------------------- ValueError Traceback (most recent call last) File ~\anaconda3\lib\site-packages\pandas\core\indexes\range.py:385, in RangeIndex.get_loc(self, key, method, tolerance) 384 try: --> 385 return self._range.index(new_key) 386 except ValueError as err: ValueError: 5 is not in range The above exception was the direct cause of the following exception: KeyError Traceback (most recent call last) Input In [17], in <cell line: 1>() 1 for colum_count in range(colum_counts): 2 for index_count in range(index_counts): ----> 3 df_copy[index_count][colum_count]=(df[index_count][colum_count]-df_mean[colum_count])/df_std[colum_count] File ~\anaconda3\lib\site-packages\pandas\core\series.py:958, in Series.__getitem__(self, key) 955 return self._values[key] 957 elif key_is_scalar: --> 958 return self._get_value(key) 960 if is_hashable(key): 961 # Otherwise index.get_value will raise InvalidIndexError 962 try: 963 # For labels that don't resolve as scalars like tuples and frozensets File ~\anaconda3\lib\site-packages\pandas\core\series.py:1069, in Series._get_value(self, label, takeable) 1066 return self._values[label] 1068 # Similar to Index.get_value, but we do not fall back to positional -> 1069 loc = self.index.get_loc(label) 1070 return self.index._get_values_for_loc(self, loc, label) File ~\anaconda3\lib\site-packages\pandas\core\indexes\range.py:387, in RangeIndex.get_loc(self, key, method, tolerance) 385 return self._range.index(new_key) 386 except ValueError as err: --> 387 raise KeyError(key) from err 388 self._check_indexing_error(key) 389 raise KeyError(key) KeyError: 5

該当のソースコード

for colum_count in range(colum_counts): for index_count in range(index_counts): df_copy[index_count][colum_count]=(df[index_count][colum_count]-df_mean[colum_count])/df_std[colum_count]

試したこと

どこから間違っているのかもわかりません。
そもそも論文では60×160というサイズ表記で9600次元のところもRGBのデータがないのがよくわかっていません。
わかることがあれば些細なことでも教えていただけると助かります。

補足情報(FW/ツールのバージョンなど)

ここにより詳細な情報を記載してください。

コメントを投稿

0 コメント