首页 文章

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

提问于
浏览
6

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

3 回答

  • 12

    关于SO的一些相关问题讨论了修改图像的方法 . 以下是两种通用方法:

    1. Modify the image data directly: 我在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. Plot the image and the lines, then turn the axes/figure into a new image: zellus' answer中的link to Steve Eddins' blog显示了如何绘制图像并向其添加线条的示例 . 但是,如果要在显示的图像上保存或执行处理,则必须将显示的图像保存为图像矩阵 . 在其他SO问题中已经讨论了如何做到这一点:

  • 3

    Superimposing line plots on images来自博客'Steve on Image Processing'有一个很好的例子,可以在图像上覆盖网格 .

  • 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
    

相关问题