0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【画像処理100本ノックに挑戦】Q.25. 最近傍補間

Last updated at Posted at 2019-12-18

使用したライブラリ

【画像処理100本ノック】独自の画像入出力クラスを作る

Q.25. 最近傍補間

最近傍補間により画像を1.5倍に拡大せよ。

関数のスケール変換の式をそのまま使うだけです。普段はバイリニア補間等を使うので実装したことはありませんが、簡単ですね。問題文記載の式は間違っているので注意が必要です(x/ax->x/a,y/ay->y/aが正しい)。

int main()
{
	PPM ppm("imori.pnm");
	int width = ppm.Get_width();
	int height = ppm.Get_height();

	double a = 1.5;
	int Width = width * a, Height = height * a;

	PPM ppm2(Width, Height);
	for(int j=0; j<Height; j++)
		for (int i = 0; i < Width; i++)
		{
			ppm2(i, j, 'r') = ppm(std::round(i / a), std::round(j / a), 'r');
			ppm2(i, j, 'g') = ppm(std::round(i / a), std::round(j / a), 'g');
			ppm2(i, j, 'b') = ppm(std::round(i / a), std::round(j / a), 'b');
		}
	ppm2.Flush("out.ppm");
	return 0;
}

imori.png out.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?