配列をイメージ表示さ​せた際に、格子線を表​示させる方法について

7 views (last 30 days)
hyhy
hyhy on 9 Jun 2022
Commented: hyhy on 10 Jun 2022
A = rand(5)
B = A < 0.5
image(B)
例えば、上記のような2値画像を表示させる際に、カラー付きの格子線(グリッドがはっきり見えるような外線)も表示させたいのですが、方法がありますでしょうか。
よろしくお願いいたします。

Accepted Answer

Atsushi Ueno
Atsushi Ueno on 9 Jun 2022
>カラー付きの格子線(グリッドがはっきり見えるような外線)も表示させたい🤔
A = rand(5); % 質問のプログラムより
B = A < 0.5; % 質問のプログラムより
imagesc(B); % image関数よりimagesc関数の方が便利です
line(repmat([0.5:1:5.5],2,1), repmat([0;5.5], 1, 6), 'Color', 'red', 'LineWidth', 5); % vertical
line(repmat([0;5.5], 1, 6), repmat([0.5:1:5.5],2,1), 'Color', 'red', 'LineWidth', 5); % horizontal
ax = gca;
% ax.XAxis.Visible = 'off'; ax.YAxis.Visible = 'off'; % を実行すると黒の数値軸が非表示になります
ax.TickLength = [0 0]; % 上記line関数の数値を理解しやすいので数値軸の表示を残しました
A = rand(5); % 質問のプログラムより
B = A < 0.5; % 質問のプログラムより
[X,Y] = meshgrid(1:5);
figure;
h_surf = gridplot([X(:),Y(:),B(:)*255]); % Grid plot version 1.2.0.0 by Mohammad Ali
h_surf.EdgeColor = 'r';
h_surf.LineWidth = 5;
ax = gca;
% ax.XAxis.Visible = 'off'; ax.YAxis.Visible = 'off'; % を実行すると黒の数値軸が非表示になります
  1 Comment
hyhy
hyhy on 10 Jun 2022
ご回答ありがとうございます。
上手く実行することが出来ました。助かりました。

Sign in to comment.

More Answers (1)

Hernia Baby
Hernia Baby on 9 Jun 2022
格子線がどのようなものかイメージできていません
ただし頂いた例で白黒はっきり見る方法はあります
A = rand(50);
B = A < 0.7;
IMG = uint8(B).*255;
imshow(IMG,'InitialMagnification','fit')

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!