MATLAB: How to declare a specified row in an image as a variable

digital image processingimage analysisimage processingImage Processing Toolboximage segmentation

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);

Best Answer

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));
Related Question