How to use "regionprops" function on true color image?!

Hey Everybody, hope you are all doing well;
i am trying to get the Max and mean intensity through regionprops function using the following command:
CC = bwconncomp(Img.jpg);
Label2=labelmatrix (CC);
rgb_labeled=label2rgb(Label2);
imshow(rgb_labeled);
but receive the following Error message:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
??? Error using ==> iptcheckinput
Function LABEL2RGB expected its first input, L, to be two-dimensional.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Regarding that when i entered the image as and RGB or intensity (gray) image as an input for regionprops function, the following error displayed..
Error message:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
??? Error using ==> regionprops>getPropsFromInput at 1172
REGIONPROPS needs I as an input to calculate 'MaxIntensity'.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Waiting your help, thanks A lot...

4 Commenti

If your image is RGB, then what is it that you intend that bwconncomp() should do with the image? Keeping in mind that the "bw" in the function name is hinting at "black and white" -- hinting that each entry in the matrix contains the entire intensity information for a pixel, and thus that a 3D matrix is to be considered in spacial terms, the green plane "above" the red one, and the blue plane "above" the green one.
Dr. Walter Roberson; I am very thankful for always replaying my questions... :)
it's ok i know that the "bw" in the function name is hinting at "black and white but i found the above listed commands as method of labeling an RGB image so i thought that i have to convert it to double then back to rgb...
Thanks...
Oh, I'm not a doctor, but if you have some spare honorary degrees you might be able to persuade me to change that.
if you are helping people,so you deserve it...
Thank you :)

Accedi per commentare.

Risposte (2)

You need to extract the color channels:
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
and then do regionprops on each color channel one at a time.

12 Commenti

If you want to do color segmentation, see demos in my File Exchange: http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862
Thanks for replaying me...
Unfortunately it doesn't work... may i do something wrong
Code%%
R = rgbImage(:, :, 1);
Pdata = regionprops(R,'MaxIntensity','MeanIntensity');
Error%%
??? Error using ==> iptcheckinput Function REGIONPROPS expected its first input, L, to be integer-valued.
Error in ==> regionprops at 142 iptcheckinput(L, {'numeric'}, ...
anyway i will search again but please if you have any note upon my comment please report me...
Really i am thankful for your support :)..
You need to pass a binary image in, not a grayscale image. You need to do something to segment your image into foreground and background. See the image segmentation demo in my File Exchange like I recommended already.
Please post your image so I can see if it's a color image with colors, or perhaps a color image that has only gray colors in it (which happens often) so that you think it should be grayscale but it's actually color. And you don't do
CC = bwconncomp(Img.jpg);
you need to pass a binary image into bwconncomp(), not a structure, which is what Img.jpg is, unless it's in single quotes in which case it would be a string (filename) which is still wrong. It must be a binary image, not a filename.
Mariam Sheha
Mariam Sheha il 25 Giu 2013
Modificato: Image Analyst il 25 Giu 2013
look i had segment the image, labeled it's binary version and already got all the geometric features out of 'regionprops' as (centroid, bounding box, perimeter,.... ).
Now i want to get ('MaxIntensity','MeanIntensity'), suppose to be for colored (RGB) version not binary, so that , i am trying to label that colored image so i can add the label as an input for regionprops function to sort out my data which is pixel'MaxIntensity','MeanIntensity'...
find the attached the used segmented image...
I tried to add image, but i don't know how?
If you want the mean or max intensity, you have to pass in the gray image into regionprops() in addition to the binary image (see the documentation). You will call it 3 times each with a different monochrome image: once with the red channel image, once with the green channel image, and once with the blue channel image.
With regards to the sample image you tried to link to: We cannot access images that are stored on your desktop. You will need to upload it to a publicly available place.
Is that what you mean?!
Regarding that CR is segmented RGB image..
R=CR(:,:,1);
G=CR(:,:,2);
B=CR(:,:,3);
Rdata = regionprops(R,'MaxIntensity','MeanIntensity');
Gdata = regionprops(G,'MaxIntensity','MeanIntensity');
Bdata = regionprops(B,'MaxIntensity','MeanIntensity');
I tried that way but it , doesn't work
Thank you
It's the sample image..
Thanks for informing me how to upload image..
Really I am Thankful for too much support u all do.. :)
Miriam, again, you need to run regionprops() with a binary image. And if you want intensity info, you'll have to pass in the gray scale image also. Here, run this code and study what it does:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures if you have the Image Processing Toolbox.
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 a standard MATLAB color demo image.
folder = 'D:\Temporary stuff';
baseFileName = 'es8u.jpg';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')
% Didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
rgbImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = 3.
[rows, columns, numberOfColorBands] = size(rgbImage);
% Display the original color image.
subplot(2, 3, 1);
imshow(rgbImage);
title('Original Color Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
% Display the color channels
subplot(2, 3, 4);
imshow(redChannel);
title('Red Channel Image', 'FontSize', fontSize);subplot(2, 3, 2);
subplot(2, 3, 5);
imshow(greenChannel);
title('Green Channel Image', 'FontSize', fontSize);subplot(2, 3, 2);
subplot(2, 3, 6);
imshow(blueChannel);
title('Blue Channel Image', 'FontSize', fontSize);
% Let's compute and display the histogram.
[pixelCount, grayLevels] = imhist(greenChannel);
% Suppress pure black so we can see the histogram.
pixelCount(1) = 0;
subplot(2, 3, 2);
bar(pixelCount);
grid on;
title('Histogram of Green Channel', 'FontSize', fontSize);
xlim([0 grayLevels(end)]); % Scale x axis manually.
% Create a binary image
binaryImage = greenChannel > 13;
% Fill holes
binaryImage = imfill(binaryImage, 'holes');
% Get rid of small specks.
binaryImage = bwareaopen(binaryImage, 10000);
subplot(2, 3, 3);
imshow(binaryImage);
title('Binary Image', 'FontSize', fontSize);
% Get the mean of the red and blue channel
% within the white pixels of the binary image using one method.
redMean = mean(redChannel(binaryImage))
blueMean = mean(blueChannel(binaryImage))
% Get the mean of the green channel
% within the white pixels of the binary image using one method.
measurements = regionprops(binaryImage, greenChannel, 'MeanIntensity');
greenMean = measurements.MeanIntensity
message = sprintf('The mean red intensity = %.2f.\nThe green mean = %.2f.\nThe mean blue intensity = %.2f.',...
redMean, greenMean, blueMean);
uiwait(helpdlg(message));

Accedi per commentare.

@Image Analyst i want to ask other question , i'm working on attached image to extract subimages of handwritten alphabets , In first row there are computerized and in second row there are handwritten alphabets. i'm cropping alphabets using boundingbox property of regionprops and saving in corresponding folder. The problem is by default it is starting from left side and moving vertically,i want it should move row wise and just take 2nd,4rth,6th,8th,10th and 12th row and sholud ignore other rows. please guide me how to do so

1 Commento

You can use kmeans() to identfy the centroids rows and columns. Then assign new labels.

Accedi per commentare.

Categorie

Richiesto:

il 14 Giu 2013

Commentato:

il 21 Gen 2021

Community Treasure Hunt

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

Start Hunting!

Translated by