2017-10-08 6 views
0

私は256x256x3マトリックスを使ってグラデーションイメージを作成するように求めている課題を完了しようとしています。マトリックス(:,:,2)の第2層は、勾配画像の緑色を生成するために使用される。3隅のグラデーションを使ってMatlab行列を作成するには?

ここ

Green matrix layer

は、私がこれまで試したものです::緑色の層がこのように見えることになっている

green = linspace(1,0,256); 

image = zeros(256,256,3) 
for column = 1:256 
    image(column, :, 2) = green; 
    image(:, column, 2) = green; 
end 

しかし、これは緑色の層マトリックスは次のように見えるように終わる: Incorrect Green Layer

私は本当に何をすべきかわかりません。どのように私はそれのように見えるマトリックスを作ることができますか?

答えて

0

OPの説明から、問題は2次元補間になります(原点では255、他の3つの頂点では0)。したがって、我々は、タスクを達成するために補間関数を使用することができます。

[X,Y] = ndgrid(0:255,0:255); %//create a grid with coordinates 
[Xi,Yi] = ndgrid([0,255],[0,255]); %//define edge coordinates 
Zi = [255,0;0,0]; %//specify green intensity at edges 
Z = interpn(Xi,Yi,Zi,X,Y); %//do linear interpolation 
Zim = uint8(round(Z)); %//round and convert to integers 
imshow(cat(3,zeros(size(Zim)),Zim,zeros(size(Zim)))) %//show result 

結果がこれです:グレースケールで

enter image description here

または、:

enter image description here

関連する問題