how to get horizontal projection and vertical projection of histogram of an binary image ? can any tell me how to get these things ?

7 ビュー (過去 30 日間)
  • how to get these type of histograms can any one tell me and thanks advance >>>!
how to get histogram projection for below image ?can any one tell me how to do it this type of histograms and see my example outputs
  • clear all; close all; a=imread('prewitresult.jpg'); bw = 1-im2bw(a); h = sum(bw,2); figure,plot(sum(bw,2),1:size(bw,1));

回答 (3 件)

Image Analyst
Image Analyst 2017 年 2 月 14 日
There is no histogram there. Those are not histograms. Those are projections using the sum() operation. Do it like this:
verticalProfile = sum(binaryImage, 2);
horizontalProfile = sum(binaryImage, 1);
  4 件のコメント
DB
DB 2017 年 2 月 16 日
編集済み: DB 2017 年 2 月 16 日
I want this type of histogram projections and I'm tried you are code but did not get this type of histogram projections
i'm tried both codes what you are suggest me but i get this type of histogram projection , so please tell me how to histogram projections define in plots ....?
Image Analyst
Image Analyst 2018 年 10 月 6 日
If you want "solid" plots, use bar() and barh() and reverse the y axis for the vertical profile:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
%===============================================================================
% Read in gray scale demo image.
folder = pwd; % Determine where demo folder is (works with all versions).
baseFileName = 'robertresult.jpg';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% The file doesn't exist -- didn't find it there in that folder.
% Check the entire search path (other folders) for the file by stripping off the folder.
fullFileNameOnSearchPath = baseFileName; % No path this time.
if ~exist(fullFileNameOnSearchPath, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
rgbImage = imread(fullFileName);
% Get the dimensions of the image.
% numberOfColorChannels should be = 1 for a gray scale image, and 3 for an RGB color image.
[rows, columns, numberOfColorChannels] = size(rgbImage)
if numberOfColorChannels > 1
% It's not really gray scale like we expected - it's color.
% Use weighted sum of ALL channels to create a gray scale image.
% grayImage = rgb2gray(rgbImage);
% ALTERNATE METHOD: Convert it to gray scale by taking only the green channel,
% which in a typical snapshot will be the least noisy channel.
grayImage = rgbImage(:, :, 1); % Take red channel.
else
grayImage = rgbImage; % It's already gray scale.
end
% Now it's gray scale with range of 0 to 255.
% Display the image.
subplot(2, 2, 1);
imshow(grayImage, []);
title('Original Image', 'FontSize', fontSize, 'Interpreter', 'None');
axis('on', 'image');
hp = impixelinfo();
%------------------------------------------------------------------------------
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
% Get rid of tool bar and pulldown menus that are along top of figure.
% set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
drawnow;
% Get the horizontal profile:
horizontalProfile = sum(grayImage, 1);
% Display the profile.
subplot(2, 2, 2);
bar(1:columns, horizontalProfile, 'FaceColor', 'k');
grid on;
xlabel('Column', 'FontSize', fontSize);
ylabel('Count', 'FontSize', fontSize);
title('Horizontal Profile', 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
% Get the vertical profile:
verticalProfile = sum(grayImage, 2);
% Display the profile.
subplot(2, 2, 3:4);
barh(1:rows, verticalProfile, 'FaceColor', 'k');
xlabel('Count', 'FontSize', fontSize);
ylabel('Row', 'FontSize', fontSize);
% Flip the y axis
ax = gca
ax.YDir = 'reverse';
grid on;
title('Vertical Profile', 'FontSize', fontSize, 'Interpreter', 'None');

サインインしてコメントする。


Jimmy Hasugian
Jimmy Hasugian 2018 年 3 月 14 日
You can try this..
verticalProfile = sum(binaryImage, 2);
horizontalProfile = sum(binaryImage, 1);
figure; bar(horizontalProfile);
figure; barh(verticalProfile);
  1 件のコメント
Eduardo Martins
Eduardo Martins 2018 年 10 月 4 日
Nice, this works for me. Thank you very much.
im = imread('kart.jpeg'); gray=rgb2gray(im);
imshow(im); imshow(gray);
bw=imbinarize(gray, 0.4);
imshow(bw);
verticalProfile = sum(bw, 2); horizontalProfile = sum(bw, 1); figure; bar(horizontalProfile); figure; barh(verticalProfile);

サインインしてコメントする。


galang rambu anarqi
galang rambu anarqi 2018 年 10 月 6 日
thanks

カテゴリ

Help Center および File ExchangeConvert Image Type についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by