b422. Colorful Life and Monochromatic Life
標籤 : 影像處理
通過比率 : 177人/195人 ( 91% ) [非即時]
評分方式:
Tolerant

最近更新 : 2022-10-27 19:43

內容

A famous advertisement slogan says, "If liver is healthy, then life is colorful. If liver is ill, then life is black and white." A healthy person and a ill person may get different feelings within the same view. In order to understand the difference, you are asked to transform a colorful image to a grayscale image. The transform formula for each pixel is:

round( (RED + GREEN + BLUE) / 3) = GRAY

RED, GREEN, and BLUE stands for the intensity level of the colorful image. Similiarly, GRAY stands for the intensity level of the grayscale image.

「肝若是好,人生是彩色的;肝若不好,人生是黑白的。」身心健康的人和不健康的人,對於世界的感受通常有很大的差異。為了讓各位深刻體會這份差異,現在要請大家將一張彩色圖片轉換成灰階圖片。轉換的方式如下:

round( (RED + GREEN + BLUE) / 3) = GRAY

round是指四捨五入至個位數。RED、GREEN、BLUE是指彩色圖片的像素亮度,GRAY是指灰階圖片的像素亮度。

輸入說明

Input contains several test cases. Each case begins with two integers W and H (1 <= W, H <= 256) which presents the width and height of the colorful image. In following H lines, each line contains W pixels. A pixel is composed of three integer R, G, B (0 <= R, G, B <= 255) which presents the RED, GREEN, and BLUE intensity level. All integers in the same line are seperated by single space.

第一行是兩個整數 W H (1 <= W, H <= 256),是圖片的寬和高。接下來的 H 行,每行有 W*3 個整數,是每個像素的 RGB 值 (0 <= R, G, B <= 255)。
 

輸出說明

Input and output format are identical. For each pixel in the output, assign the same intensity level to r, g and b with corresponding grayscale intensity level.

輸出與輸入格式一樣。請輸出轉換過的圖片。
 

範例輸入 #1
3 2
1 2 3 4 5 6 7 8 9
10 11 12 13 14 15 16 17 18
範例輸出 #1
3 2
2 2 2 5 5 5 8 8 8
11 11 11 14 14 14 17 17 17
測資資訊:
記憶體限制: 64 MB
公開 測資點#0 (33%): 1.0s , <1K
公開 測資點#1 (33%): 1.0s , <1M
公開 測資點#2 (34%): 1.0s , <1M
提示 :

1. 描述圖片大小時,大家一律使用寬高,而不是高寬(例如矩陣)。因此輸入第一行是寬高。
2. 這裡提供一個例子,轉換前和轉換後擁有明顯的差異。有興趣的人,可以進一步參考維基百科的「色盲」介紹。

標籤:
影像處理
出處:
[管理者: DJWS (...) ]

本題狀況 本題討論 排行

編號 身分 題目 主題 人氣 發表日期
26779 406490150@gm ... (我是朱朱) b422
498 2021-08-24 20:43
16868 freedom50199 ... (帥氣魔方生) b422
技巧
1045 2019-02-15 01:11