In matlab, how to draw a grid over an image

How to draw a grid over an image. It should become part of this image. It should be able to show some rows and columns above the image itself. You can specify rows for rows and columns. In fact, I was inspired by how a research paper discusses the results that they have about image deformation. One of the links is: http://www.hammerhead.com/thad/morph.html

+6
image-processing matlab
source share
3 answers

SO discusses a number of related issues that discuss ways to change the image. Here are two common approaches:

1. Change the image data directly: I discuss this in my answer to this other SO question . Because image data can be 2-D or 3-D , you can use multidimensional indexing to modify the raw image data by creating rows along specified rows and columns. Here's an example that changes every 10 rows and columns of an image to black:

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

And now the image data in the img variable has black lines on it, and you can write them to a file or do any other processing you want.

2. Build the image and lines, then rotate the axis / figure into a new image: The zellus answer link shows an example of how you can build an image and add lines to it. However, if you want to save or process the displayed image, you need to save the displayed image as an image matrix. How you can do this has been discussed in these other SO issues:

  • How to save a modified image in MATLAB?
  • Rotate Matlab Graph into Image
+10
source share

Overlaying string images on images from the Steve on Image Processing blog has a nice example when overlaying an image on a grid.

+3
source share

Actually, I looked at this question after executing this code with my own ... the code reads the image and draws a grid on the image with each input parameter

I hope this will benefit :)

See 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 
+1
source share

All Articles