簡體   English   中英

如果圖像如何着色傅立葉變換

[英]How to colourize Fourier transform if image

我已經編寫了一個計算FFT的應用程序,我想知道一種可視化彩色光譜的好方法。

不幸的是,我的幼稚嘗試並沒有取得好的結果。 我想實現以下目標:

圖片

我目前正在使用它進行着色

float r = std::log( std::abs(source[u][v]) + 1 ) * 0.2f;
float g = std::log( std::max(std::abs(source[u][v]) - 10.0f, 0.0f) + 1 ) * 0.2f;
float b = std::log( std::max(std::abs(source[u][v]) - 100.0f, 0.0f) + 1 ) * 0.2f;

我提出以下方法。 首先,選擇一個最大值(代表“紅色”的那個)並按[0,1]間隔縮放所有值。 接下來,將此值用於色相,並使用HSL到RGB轉換。 Python代碼如下所示:

import colorsys
from PIL import Image, ImageDraw

w = 400
h = 20
im = Image.new("RGB", (w, h))
draw = ImageDraw.Draw(im)

for x in range(0, 100):
    value = float(x)/100

    r, g, b = colorsys.hsv_to_rgb(1-value*3/4-0.33, 1, 1)
    color = int(r*255), int(g*255), int(b*255)
    draw.rectangle((x * 4, 0, (x + 1) * 4, h), color, color)

im.save('example.png' , 'png')

結果:

將[0,1]中的值映射到顏色

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM