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

조회 수: 4 (최근 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');

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by