Histogram-based RGB segmentation

10 ビュー (過去 30 日間)
Teshan Rezel
Teshan Rezel 2020 年 2 月 6 日
コメント済み: Teshan Rezel 2020 年 2 月 7 日
Hi All,
I'm trying to segment an RGB image based on it's histograms; my code is as follows:
%Split into RGB Channels
Red = img(:,:,1);
Green = img(:,:,2);
Blue = img(:,:,3);
%Get histValues for each channel
[yRed, x] = imhist(Red);
[yGreen, x] = imhist(Green);
[yBlue, x] = imhist(Blue);
%Plot them together in one plot
plot(x, yRed, 'Red', x, yGreen, 'Green', x, yBlue, 'Blue');
histRGB = hist([imhist(Red), imhist(Green), imhist(Blue)]);
histMask = img.*uint8(histRGB);
imshow(histMask)
I get the following error when compiling this section: "Array dimensions must match for binary array op." I'm not sure how to fix this, as I'm not well versed in Matlab currently.
Any help will be appreciated!
Thanks

採用された回答

Subhadeep Koley
Subhadeep Koley 2020 年 2 月 6 日
I am not sure about which algorithm you are trying to implement but below is an example of histogram based segmentation using Otsu's method.
clc; close all;
% Read image into the workspace
img = imread('peppers.png');
% Calculate a 255-bin histogram for the image
[counts, ~] = imhist(rgb2gray(img), 255);
% Compute a global threshold using the histogram counts
T = otsuthresh(counts);
% Create a binary image using the computed threshold
BW = imbinarize(rgb2gray(img), T);
% Display the image
figure; imshowpair(img, BW, 'montage');
  1 件のコメント
Teshan Rezel
Teshan Rezel 2020 年 2 月 7 日
Thanks Subhadeep, much appreciated!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeHistograms についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by