2010-11-15 64 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