how to declare a specified row in an image as a variable?

1 回表示 (過去 30 日間)
Sean
Sean 2015 年 3 月 4 日
コメント済み: Sean 2015 年 3 月 4 日
I have a folder of images and I know which 2 rows I want to plot out and define on all of my images (rows 200 and 315). To begin with I used the following code to plot the 2 rows on one of the images:
A=imread('K1.BMP');
AR=A(:,:,1); %remove rgb, Grey scale images
%plot a green line for row 200 the whole way across the image (Image is 1024x886)
%plot a blue line for row 315 the whole way across the image
plot([0 1024],[200 200], 'g');
plot([0 1024], [315 315], 'b');
How do I declare these lines as variables so I can then plot the same line on the rest of my images? The reason I'm doing this is because I want to process all the pixels in the specified rows of the image, i.e. call row 1 'X1' and row 2 'X2' and then find its mean and standard deviation using:
meanX1 = mean(X1);
stdX1 = std(X1);
meanX2 = mean(X2);
stdX2 = std(X2);

採用された回答

Image Analyst
Image Analyst 2015 年 3 月 4 日
You mean like this:
[rows, columns] = size(AR);
y1 = 200
y2 = 315
row1 = AR(y1, :); % Extract this line of gray levels from the image.
row2 = AR(y2, :);
plot([0, columns], [y1, y1], 'g');
plot([0, columns], [y2, y2], 'b');
meanX1 = mean(row1);
stdX1 = std(double(row1));
meanX2 = mean(row2);
stdX2 = std(double(row2));

その他の回答 (1 件)

Guillaume
Guillaume 2015 年 3 月 4 日
Shouldn't your x coordinates start at 1 or 0.5
Anyway:
img = imread('cameraman.tif');
rowtoplot = 200;
imshow(img)
hold on
plot([0.5 size(img, 2)+0.5], [rowtoplot rowtoplot], 'g');
  1 件のコメント
Sean
Sean 2015 年 3 月 4 日
thanks for the feedback!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by