how to add grid to the image?

조회 수: 35 (최근 30일)
Om Gurav
Om Gurav 2016년 10월 24일
편집: Image Analyst 2022년 6월 18일
I have a gray-scale image which is in .tif format. I opened it in MATLAB using imread command. Now i want to add grid as x and y axes in terms of its pixels. this image is of 1024*1024 pixels. Please help.
  댓글 수: 1
Clay Swackhamer
Clay Swackhamer 2018년 10월 17일
편집: Clay Swackhamer 2018년 10월 17일
If you are still working on this I wrote a simple function to put a grid on an image. It is on the file exchange here

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2016년 10월 24일
You can overlay lines:
[rows, columns, numberOfColorChannels] = size(yourImage);
hold on;
lineSpacing = 20; % Whatever you want.
for row = 1 : stepSize : rows
line([1, columns], [row, row], 'Color', 'r', 'LineWidth', 1);
end
for col = 1 : stepSize : columns
line([col, col], [1, rows], 'Color', 'r', 'LineWidth', 1);
end
  댓글 수: 6
Pablo Meseguer Esbri
Pablo Meseguer Esbri 2022년 6월 18일
That was very helpful! Thank you!
Image Analyst
Image Analyst 2022년 6월 18일
편집: Image Analyst 2022년 6월 18일
@Pablo Meseguer Esbri, thanks for the nice comment.
You can now use xline and yline instead of line to draw lines in the overlay. It will be simpler code. I'm pretty sure you don't even need to put hold on if you use xline and yline.
[rows, columns, numberOfColorChannels] = size(yourImage);
lineSpacing = 20; % Whatever you want.
for row = 1 : stepSize : rows
yline(row, 'Color', 'r', 'LineWidth', 1);
end
for col = 1 : stepSize : columns
xline(col, 'Color', 'r', 'LineWidth', 1);
end

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by