MATLAB Answers


How to extract particular pixel values from an image?

Asked by Nikhil
on 24 Dec 2012


I'm doing project on image processing, and in one of my module i need to extract the particular bunch of the pixels.I know the values of that pixel but i'm not getting how exactly to extract that values. so please help me to get out of this!


Walter Roberson
on 24 Dec 2012

What do you mean by "extract" in this case?

Are the pixels RGB or grayscale?

on 26 Dec 2012

sir, here extract means retrieval of those pixels, i mean only "1". and its a grayscale image and i converted it into binary image. how can i do this, please guide me!

3 Answers

Answer by Walter Roberson
on 24 Dec 2012
[PixelRows, PixelColumns] = find( YourImage(:,:,1) == RedValue & YourImage(:,:,2) == GreenValue & YourImage(:,:,3) == BlueVaue );


Answer by Nikhil
on 24 Dec 2012

sir i appreciate your answer but my image is binary image, sorry i completely forgot to mention it!! Now what to do??


on 26 Dec 2012 sir here you can see the database which i'm using for my project work.

on 2 Jan 2013

Dear Nikhil, Are you sure those are the images or they are just for example??...if so, please share the original image you are working on through or picasa, tiny pic or any other photo sharing site...

Also, I feel that the labeling of image will be helpful for you..try image labeling once you label the regions of your image, it will be relatively easy to extract them...try once this might be helpful...

on 2 Jan 2013

Kris Sir, which link i had mentioned above that is database link, i mean the same database using for my project. and for further work i need to delete/remove the background but i got stuck here only.

how can i do this??

Answer by Image Analyst
on 24 Dec 2012

You say

  1. You have a binary image (which means value of 0 and 1)
  2. You know the values in the particular bunch (either 0, 1, or both of course)
  3. You need to extract their values (which will again be either 0 or 1 or both)

So the question remains,

  1. Do you know the locations of the "particular bunch" of pixels?
  2. If you already know their values then what exactly does it mean that you need to extract their values? You mean you want a vector that is the length of the "particular bunch" and has the 0 or 1 values in the vector? Like your image is 1 megapixel but you want a vector of pixel values from a small 1000 pixel chunk in the image?


on 2 Jan 2013

sir will you please mention what the value should i write in the function you mentioned above? i mean in the below function..

imagesc(YourImageData, 'Alphadata', YourImageData)


Walter Roberson
on 2 Jan 2013

What is the name of your black-and-white image array?

Discover MakerZone

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

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!