user3500001
user3500001

Reputation: 19

How to convert matlab image into 2d line graph

I currently have a set of grayscale images that i would like to represent as 2D graphs. Ideally each vertical column of pixels would have a mean colour based on how dark they are, and this would be represented by a point on the Y axis of a line graph. Any advice on how to achieve this would be massively helpful. Thanks!

Upvotes: 1

Views: 1634

Answers (1)

Cape Code
Cape Code

Reputation: 3574

Load and turn your RGB image into grayscale as follows:

CH3=rgb2gray(imread('CH3.bmp'));

You can then compute the mean of the columns of an array (images are 2D arrays of pixels) with the mean function:

AvgCh3=mean(CH3, 1);†

AvgCh3 is now a 1D vector containing the averages over each corresponding column. Plot it with the plot function:

plot(AvgCh3)

Here is a graphical example:

sine and its value

† MATLAB has a different convention for rows and columns of arrays and dimensions in an image, choosing the 1st dimension of the mean function on an image will compute the average along the height of the image.

Upvotes: 1

Related Questions