在matlab中,如何在图像上绘制网格

时间:2010-11-15 06:20:16

标签: matlab image-processing

如何在图像上绘制网格。它应该成为该图像本身的一部分。 它应该能够在图像本身上显示一些行和列。可以指定行和列的行。 实际上,我对一些研究论文讨论他们关于图像变形的结果的方式感到鼓舞。其中一个链接是:http://www.hammerhead.com/thad/morph.html

3 个答案:

答案 0 :(得分:13)

有很多关于SO的相关问题,讨论了修改图像的方法。以下是两种通用方法:

<强> 1。直接修改图像数据:我在my answer to this other SO question中讨论了这个问题。由于图像数据可以是2-D or 3-D,因此您可以使用multidimensional indexing修改原始图像数据,沿给定的行和列创建线条。这是一个将图像中的每10行和每列更改为黑色的示例:

img = imread('peppers.png');  %# Load a sample 3-D RGB image
img(10:10:end,:,:) = 0;       %# Change every tenth row to black
img(:,10:10:end,:) = 0;       %# Change every tenth column to black
imshow(img);                  %# Display the image

alt text

现在变量img中的图像数据上有黑线,您可以将其写入文件或进行其他任何处理。

<强> 2。绘制图像和线条,然后将轴/图形转换为新图像: link to Steve Eddins' blog中的zellus' answer显示了如何绘制图像并向其添加线条的示例。但是,如果要在显示的图像上保存或执行处理,则必须将显示的图像保存为图像矩阵。在其他SO问题中已经讨论了如何做到这一点:

答案 1 :(得分:3)

来自博客“Steve on Image Processing”的

Superimposing line plots on images有一个很好的例子,可以将网格覆盖在图像上。

答案 2 :(得分:1)

实际上我在自己编写代码之后看了这个问题....代码读取图像并在图像上绘制每个输入参数的网格

我希望它会有任何好处:)

观看matlab代码:

function [ imageMatdouble ] = GridPicture( PictureName , countForEachStep )
 %This function grid the image into counts grid 
pictureInfo = imfinfo(PictureName);     %load information about the input 

 [inputImageMat, inputImageMap] = imread(PictureName);        % Load the image     

 if (pictureInfo.ColorType~='truecolor')
    warning('The function works only with RGB (TrueColor) picture');
    return 
 end

%1. convert from trueColor(RGB) to intensity (grayscale)
 imageMat = rgb2gray(inputImageMat);   

%2. Convert image to double precision.
 imageMatdouble =im2double(imageMat);  

 % zero is create indicated to black 
 height = pictureInfo.Height ; 
 width = pictureInfo.Width
  i=1;j=1;  
 while (i<=height ) 
     for j=1:width
         imageMatdouble(i,j)=1;
    end
    j=1;
    if (i==1)
       i=i+countForEachStep-1;
   else 
       i=i+countForEachStep;
   end
  end


   i=1;j=1;  
  while (i<=width ) 
  for j=1:height
      imageMatdouble(j,i)=1;
   end
  j=1;
  if (i==1)
      i=i+countForEachStep-1;
  else 
       i=i+countForEachStep;
   end

 end

 imwrite(imageMatdouble,'C:\Users\Shahar\Documents\MATLAB\OutputPicture.jpg')



 end
相关问题