【问题标题】:In matlab, how to draw a grid over an image在matlab中,如何在图像上绘制网格
【发布时间】:2017-05-07 11:41:53
【问题描述】:

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

【问题讨论】:

    标签: matlab image-processing


    【解决方案1】:

    有许多关于 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
    

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

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

    【讨论】:

    • 我觉得'1.直接修改图像数据'中的示例代码有点简单。 “2.Plot the image and line ...”部分也很有帮助。
    【解决方案2】:

    来自博客“Steve on Image Processing”的Superimposing line plots on images 有一个很好的例子,可以在图像上叠加网格。

    【讨论】:

    • 谢谢,这是我看到的最简单的例子。
    【解决方案3】:

    其实我是在自己做完这段代码后才看到这个问题的....代码读取一个图像并在每个输入参数的图像上绘制网格

    我希望它会有所帮助:)

    观看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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-20
      • 1970-01-01
      • 2012-01-02
      • 2013-12-20
      相关资源
      最近更新 更多