MATLAB Answers

how to plot gray-level value versus image height

Asked by Elysi Cochin on 16 Jan 2013

i have uploaded an image in the link

in that fig(b) says to plot gray-level value versus image height.... how to plot gray-level value versus image height as shown in that figure(b) and how to get those values R1 and R2 from that... please do reply sir.... i need to get the region between R1 and R2 and draw lines in R1 and R2 as in figure(c) and display that much portion in another figure..... please do reply....



No products are associated with this question.

1 Answer

Answer by Thorsten
on 16 Jan 2013
 Accepted answer
Iorg = imread('./../../Downloads/r1r2.png');
I = rgb2gray(Iorg(58:242, 60:198, :));
s = sum(I');
[notused R1] = max(s);
minthreshold = 30;
R2 = min(find(s  < minthreshold));
subplot(2, 3, [1:3]), imshow(Iorg)
subplot(2,3,4), imshow(I)
% plot vertical histogram
N = numel(s);
for i=1:N, line([0 s(i)], N-[i i]+1), end
axis tight
set(gca, 'PlotBoxAspectRatio', [1 size(I,1)/size(I, 2) 1])
xlabel('Gray-level value')
ylabel('Image height')
line(xlim, [R1 R1], 'Color', 'y')
line(xlim, [R2 R2], 'Color', 'y')


Elysi Cochin on 17 Jan 2013

thank u sir for ur reply.... sir i got the top line R1 but for R2 error is being displayed as......

??? Error using ==> line

Vectors must be the same lengths.

Error in ==> Thorsten at 33

line(xlim, [R2 R2], 'Color', 'y')

what should i do sir to rectify this error... please do reply sir.... sir the lines R1 and R2 should be plotted on Iorg so i changed to

    line(xlim, [R1 R1], 'Color', 'y')
    line(xlim, [R2 R2], 'Color', 'y')

then also line R2 is not getting displayed sir.... please do reply sir...

Walter Roberson
on 17 Jan 2013

Please show size(R1) and size(R2) and size(s)

Elysi Cochin on 17 Jan 2013

why sir.....

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!