Discover MakerZone

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

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
image processing

Subject: image processing

From: BC Tan

Date: 28 Sep, 2009 00:43:01

Message: 1 of 10

Hi All,

I got 2 images. One of the image is black and white while the other is a color image. I would like to do the following:

1) Find the histogram of each images
2) For the color image, find the histogram of each of its color channels(RGB).

I am new in matlab can anyone provide me with an example or direction for the above? thanks.

Subject: image processing

From: Sprinceana

Date: 28 Sep, 2009 07:45:03

Message: 2 of 10

For the rgb image convert it to black and white:

>> img=imread('poza1.jpg');imshow(img) % read and display rgb image
>> img2=rgb2gray(img);imshow(img2) % convert the rgb image to black and white and display it
>>imhist(img2) % display histogram of the image black and white stored in variable img2




For your image which is already black and white :

>>img3=imread('name_image.jpg');imshow(img) % read it and display it
>>imhist(img3) % display histogram of your image black and white that you have


Your image must be in work folder of matlab.

And this is the first point of your assignement.

Best wishes,

Michael

Subject: image processing

From: Sprinceana

Date: 28 Sep, 2009 07:59:02

Message: 3 of 10

2) For each channel (RGB) of your rgb image you can use functions imhist and subplot:

So in a matlab script called histo.m write this

% initialisations that enter in every matlab script
    clear all ;
    close all ;
    clc ;
 
% read your rgb image
    img= imread('name_photo.jpg') ;
 
    subplot(1,3,1) ; imhist(img(:,:,1)) ; Title('Red') ;
    subplot(1,3,2) ; imhist(img(:,:,2)) ; Title('Green') ;
    subplot(1,3,3) ; imhist(img(:,:,3)) ; Title('Blue') ;

To run your script simply press F5 or write in command window:

>>histo

Here is the full source attached here for point 2:

http://flyupload.flyupload.com/get?fid=9996206

Subject: image processing

From: ImageAnalyst

Date: 28 Sep, 2009 16:49:34

Message: 4 of 10

On Sep 27, 8:43 pm, "BC Tan" <rai...@live.com> wrote:
> Hi All,
>
> I got 2 images. One of the image is black and white while the other is a color image. I would like to do the following:
>
> 1) Find the histogram of each images
> 2) For the color image, find the histogram of each of its color channels(RGB).  
>
> I am new in matlab can anyone provide me with an example or direction for the above? thanks.

-------------------------------------------------------------------------------------------------------------
Here's a basic image processing tutorial I wrote that you may find
informative.
http://www.mathworks.com/matlabcentral/fileexchange/25157
It does a histogram of a monochrome image.

To do color histogram, you can try this code below. It will ask you
to specify an image file, then it will display the original color
image, plot the histogram of the red, green, and blue channels as
individual bar charts, then plot all 3 together on one line plot.
(Be sure to fix any line breaks introduced by the newsreader)

clc;
% clear all;
close all;
workspace;
% Change default directory to the one containing the standard demo
images for the MATLAB Image Processing Toolbox.
originalFolder = pwd;
folder = 'C:\Program Files\MATLAB\R2009b\toolbox\images\imdemos';
if ~exist(folder, 'dir')
folder = pwd;
end
cd(folder);
% Browse for the image file.
[baseFileName, folder] = uigetfile('*.*', 'Specify an image file');
fullImageFileName = fullfile(folder, baseFileName);
% Set current folder back to the original one.
cd(originalFolder);

% Read in image into an array.
rgbImage = imread(fullImageFileName);
[rows columns numberOfColorChannels] = size(rgbImage);
if strcmpi(class(rgbImage), 'uint8')
% Flag for 256 gray levels.
eightBit = true;
end
% If it's monochrome, convert it to color.
if numberOfColorChannels == 1
rgbImage = cat(3, rgbImage, rgbImage, rgbImage);
end
% Extract out the color channels
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
subplot(3,1,1);
imshow(rgbImage);
drawnow; % Make it display immediately.
if numberOfColorChannels > 1
title('Original Color Image', 'FontSize', 16);
else
title('Original Monochrome Image (converted to color)', 'FontSize',
16);
end

% Plot red
hR = subplot(3, 3, 4);
[countsR, grayLevelsR] = imhist(redChannel);
maxGLValueR = find(countsR > 0, 1, 'last');
maxCountR = max(countsR);
bar(countsR, 'r');
grid on;
xlabel('Gray Levels');
ylabel('Pixel Count');
title('Histogram of Red Channel', 'FontSize', 16);

% Plot green
hG = subplot(3, 3, 5);
[countsG, grayLevelsG] = imhist(greenChannel);
maxGLValueG = find(countsG > 0, 1, 'last');
maxCountG = max(countsG);
bar(countsG, 'g');
grid on;
xlabel('Gray Levels');
ylabel('Pixel Count');
title('Histogram of Green Channel', 'FontSize', 16);

% Plot blue
hB = subplot(3, 3, 6);
[countsB, grayLevelsB] = imhist(blueChannel);
maxGLValueB = find(countsB > 0, 1, 'last');
maxCountB = max(countsB);
bar(countsB, 'b');
grid on;
xlabel('Gray Levels');
ylabel('Pixel Count');
title('Histogram of Blue Channel', 'FontSize', 16);

% Set all axes to be the same width and height.
maxGL = max([maxGLValueR, maxGLValueG, maxGLValueB]);
if eightBit
maxGL = 255;
end
maxCount = max([maxCountR, maxCountG, maxCountB]);
axis([hR hG hB], [0 maxGL 0 maxCount]);

% Plot all
subplot(3, 1, 3);
plot(grayLevelsR, countsR, 'r', 'LineWidth', 2);
grid on;
xlabel('Gray Levels');
ylabel('Pixel Count');
hold on;
plot(grayLevelsG, countsG, 'g', 'LineWidth', 2);
plot(grayLevelsB, countsB, 'b', 'LineWidth', 2);
title('Histogram of All Channels', 'FontSize', 16);
maxGrayLevel = max([maxGLValueR, maxGLValueG, maxGLValueB]);
% Trim x-axis to just the max gray level on the bright end.
if eightBit
xlim([0 255]);
else
xlim([0 maxGrayLevel]);
end

% Maximize figure.
set(gcf, 'Position', get(0, 'ScreenSize'));

Subject: image processing

From: azizian5227@gmail.com

Date: 13 May, 2013 08:06:34

Message: 5 of 10

Hi all

hmmm. i have a image about red bloods.
so, i wanna detecting them and later , counting themi know that how i can detecting(edge commend family). but , i dont know how i can count my detected objectes with MATLAB.

Please help me

thank you

Subject: image processing

From: azizian5227@gmail.com

Date: 13 May, 2013 08:14:51

Message: 6 of 10

On Monday, May 13, 2013 12:36:34 PM UTC+4:30, azizi...@gmail.com wrote:
> Hi all
>
>
>
> hmm. i have a image about red bloods.
>
> so, i wanna detecting them and later , counting them i know how i can detecting(edge commend family). but , i don't know how i can count my detected objects with MATLAB.
>
>
>
> Please help me
>
>
>
> thank you

Subject: image processing

From: Steven_Lord

Date: 13 May, 2013 13:39:00

Message: 7 of 10



<azizian5227@gmail.com> wrote in message
news:6c470f12-52c6-4ed4-bfc2-52acab3db9b5@googlegroups.com...
> Hi all
>
> hmmm. i have a image about red bloods.
> so, i wanna detecting them and later , counting themi know that how i can
> detecting(edge commend family). but , i dont know how i can count my
> detected objectes with MATLAB.
>
> Please help me

Take a look at the Image Segmentation or Measuring Image Features examples
in Image Processing Toolbox.

http://www.mathworks.com/products/image/examples.html

If you have further questions after doing so, respond in the newsgroup
(please do NOT email me directly) with more specific details and someone may
be able to offer suggestions or answers.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: image processing

From: azizian5227@gmail.com

Date: 13 May, 2013 15:23:41

Message: 8 of 10

On Monday, May 13, 2013 6:09:00 PM UTC+4:30, Steven_Lord wrote:
> <azizian5227@gmail.com> wrote in message
>
> news:6c470f12-52c6-4ed4-bfc2-52acab3db9b5@googlegroups.com...
>
> > Hi all
>
> >
>
> > hmmm. i have a image about red bloods.
>
> > so, i wanna detecting them and later , counting themi know that how i can
>
> > detecting(edge commend family). but , i dont know how i can count my
>
> > detected objectes with MATLAB.
>
> >
>
> > Please help me
>
>
>
> Take a look at the Image Segmentation or Measuring Image Features examples
>
> in Image Processing Toolbox.
>
>
>
> http://www.mathworks.com/products/image/examples.html
>
>
>
> If you have further questions after doing so, respond in the newsgroup
>
> (please do NOT email me directly) with more specific details and someone may
>
> be able to offer suggestions or answers.
>
>
>
> --
>
> Steve Lord
>
> slord@mathworks.com
>
> To contact Technical Support use the Contact Us link on
>
> http://www.mathworks.com
hi steve
thank you

Subject: image processing

From: azizian5227@gmail.com

Date: 13 May, 2013 15:25:30

Message: 9 of 10

Hi

ok

Thank you

Subject: image processing

From: azizian5227@gmail.com

Date: 13 May, 2013 15:29:07

Message: 10 of 10

hi

OK

thank you

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us