# How to draw a graph of an image with frequency in y axis and pixel value in x axis in matlab?

8 views (last 30 days)
Anushka on 26 Jul 2015
Commented: Image Analyst on 21 Aug 2015
How to draw a graph of an image with frequency in y axis and pixel value in x axis in matlab?
Anushka on 26 Jul 2015
Share and secret are two images

Image Analyst on 26 Jul 2015
% Extract the individual red, green, and blue color channels.
redChannel = secret(:, :, 1);
greenChannel = secret(:, :, 2);
blueChannel = secret(:, :, 3);
[pixelCountsR, grayLevelsR] = imhist(redChannel);
[pixelCountsG, grayLevelsG] = imhist(greenChannel);
[pixelCountsB, grayLevelsB] = imhist(blueChannel);
plot(grayLevelsR, pixelCountsR, 'r-', 'LineWidth', 2);
hold on;
plot(grayLevelsG, pixelCountsG, 'r-', 'LineWidth', 2);
plot(grayLevelsB, pixelCountsB, 'r-', 'LineWidth', 2);
grid on;
fontSize = 20;
ylabel('Frequency', 'FontSize', fontSize);
xlabel('Pixel Value', 'FontSize', fontSize);
Then just do the same for share. Then you can use text() and annotation() to add text labels and arrows wherever you want them. Or you can use legend().
Image Analyst on 21 Aug 2015
Anushka:
Try this:
x = 0:255;
y = 0.0018 * rand(1, length(x));
plot(x, y, 'b-');
ax = gca;
ax.XTick = 0:50:250;
yTicks = 0:.0002:.0018;
ax.YTick = yTicks;
for k = 1 : length(yTicks)
YTickLabels{k} = sprintf('%.4f', yTicks(k));
end
ax.YTickLabels = YTickLabels;

Guillaume on 26 Jul 2015
doc imhist
Anushka on 26 Jul 2015
Sir I want the graph like shown below