In matlab, how to draw a grid over an image

前端 未结 3 1414
时光取名叫无心
时光取名叫无心 2020-12-10 16:12

How to draw a grid over an image. It should become part of that image itself. It should be able to show some rows and columns over the image itself. The lines for rows and c

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-10 16:41

    Actually I watched this question after doing this code by my own .... the code reads an image and draw grid on the image every input parameter

    I hope it would do any good :)

    Watch the matlab code :

    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
    

提交回复
热议问题