2010-11-15 65 views

回答

10

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.剧情图像和线,然后转动轴/图到一个新的图像:zellus' answerlink to Steve Eddins' blog示出如何可以绘制的图像,并添加行它的例子。但是,如果您想要保存或执行显示的图像的处理,则必须将显示的图像保存为图像矩阵。你如何能做到这已经在这些其他SO问题进行了讨论:

+1

我觉得'1.直接修改图像数据'中的示例代码稍微简单一些。 “2.绘制图像和线......”部分也有帮助。 – 2010-11-15 18:54:44

3

Superimposing line plots on images来自博客'史蒂夫在图像处理'有一个很好的例子,在图像上叠加网格。

+0

谢谢,这是我看到的最简单的例子。 – 2010-11-15 15:31:57

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