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:
How to edit/change the pixel color?

Subject: How to edit/change the pixel color?

From: Kevin Lan

Date: 16 Jan, 2008 01:32:03

Message: 1 of 6

Hi everyone,

Is there a way that I can change the color of a pixel? For
example, if I've got an image and I want a part of image
to change color. In matlab is there so that I can do that?

Or if someone could help me solve this question: I have
two lines that are very close to each other on an image
and I would like to "join" them. my image has only black
and white color and the lines are white. so i would like
to maybe change the color of some pixels between the lines
into white so that they look like "jointed"

Subject: How to edit/change the pixel color?

From: matt dash

Date: 16 Jan, 2008 19:04:02

Message: 2 of 6

I've never really worked with images, but this is definitely
possible. Your image should be stored as an array (either 2d
or 3d) where each pixel is represented by the corresponding
value in the array (each value matches up to a different
color). All you need to do is find the values you want to
change in the array, and change them to the value for the
color you want.

The array format will depend on if you're using a colormap
or rgb colors. If it's a colormap (probably best for a black
and white picture) then 0 is probably black, and 1 is
probably white, so if you have two lines that span the whole
image, just look for two rows/columns of all 1's. Then
change everything in between them to 1, and it'll turn
white. If you're using RGB color, it'll be a 3d array and
you'll need to change the values in all 3 arrays to 1 (each
color, red, green, and blue, will have it's own 2d array, so
you need to change the values in each of them.)

If you used a high level function from the image toolbox to
display the image, these arrays might not be in your
workspace, so try using lower level functions to find them.
(like image instead of imshow). Read "help image" for more info.

Subject: How to edit/change the pixel color?

From: Cy abd

Date: 16 Jan, 2008 19:24:02

Message: 3 of 6

look in help under:
"Binary Images"

Subject: How to edit/change the pixel color?

From: Kevin Lan

Date: 18 Jan, 2008 19:26:02

Message: 4 of 6

"matt dash" <md222@mail.gatech.edu> wrote in message
<fmlkf2$817$1@fred.mathworks.com>...
> I've never really worked with images, but this is
definitely
> possible. Your image should be stored as an array
(either 2d
> or 3d) where each pixel is represented by the
corresponding
> value in the array (each value matches up to a different
> color). All you need to do is find the values you want to
> change in the array, and change them to the value for the
> color you want.
>
> The array format will depend on if you're using a
colormap
> or rgb colors. If it's a colormap (probably best for a
black
> and white picture) then 0 is probably black, and 1 is
> probably white, so if you have two lines that span the
whole
> image, just look for two rows/columns of all 1's. Then
> change everything in between them to 1, and it'll turn
> white. If you're using RGB color, it'll be a 3d array and
> you'll need to change the values in all 3 arrays to 1
(each
> color, red, green, and blue, will have it's own 2d
array, so
> you need to change the values in each of them.)
>
> If you used a high level function from the image toolbox
to
> display the image, these arrays might not be in your
> workspace, so try using lower level functions to find
them.
> (like image instead of imshow). Read "help image" for
more info.

Thanks for replying!
But how exactly do I change the pixel values though??
I tried different ways including image and imshow but they
won't allow me to change the pixel values.

Subject: How to edit/change the pixel color?

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 18 Jan, 2008 19:35:33

Message: 5 of 6

In article <fmquga$hcr$1@fred.mathworks.com>,
Kevin Lan <kev_dxd@yahoo.com> wrote:

>But how exactly do I change the pixel values though??
>I tried different ways including image and imshow but they
>won't allow me to change the pixel values.

arrayname(index) = newpixelvalue;

then image() or imshow() the array.

Note: you might be working with indexed images, in which case the
newpixelvalue should be the new index into the colour table
rather than a new absolute pixel value. If you are working with
RGB images, then your array will be three dimensional (and the
array will never be three dimensional if you are -not- working with
RGB), in which case the new values you store will be R or G or B
components; you could update all three at once by (for example)

arrayname(x,y,:) = [1,0,0];

to set the location to be pure red with 0 green and 0 blue.


If you want to change a pixel on an existing RGB image plot directly,
then you would do it by,

  arrayname = get(imagehandle, 'CData');
  arrayname(x,y,:) = [newR, newG, newB];
  set(imagehandle, 'CData', arrayname);
--
   "Okay, buzzwords only. Two syllables, tops." -- Laurie Anderson

Subject: How to edit/change the pixel color?

From: ucd puri

Date: 22 Jan, 2009 23:00:34

Message: 6 of 6

Hi There
I am also learning and implementing Image processing in matlab. I was wondering if it is possible to change the color of few pixels (depending on some criteria) of a 16bit signed grey scale image whose brightness level varies from -32768 to +32768.

For example, i am applying tresholding to such an image, and i want to represent all the pixels in RED which are above 22345 brightness level on the same image.

I applied the method you explained above but does not work. I tried to first change my image I ie128X128 to a RGB color image by using I=cat(3,I,I,I).... and then tried to change the color, but dint work. i know i am doing a conceptual mistake, that with greyscale brightness levels, i am trying to put color in, but...that what i want.

Any idea or suggesions or help will be highly appricaiated.
Regards n thanks

 
roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in message <fmqv25$aqa$1@canopus.cc.umanitoba.ca>...
> In article <fmquga$hcr$1@fred.mathworks.com>,
> Kevin Lan <kev_dxd@yahoo.com> wrote:
>
> >But how exactly do I change the pixel values though??
> >I tried different ways including image and imshow but they
> >won't allow me to change the pixel values.
>
> arrayname(index) = newpixelvalue;
>
> then image() or imshow() the array.
>
> Note: you might be working with indexed images, in which case the
> newpixelvalue should be the new index into the colour table
> rather than a new absolute pixel value. If you are working with
> RGB images, then your array will be three dimensional (and the
> array will never be three dimensional if you are -not- working with
> RGB), in which case the new values you store will be R or G or B
> components; you could update all three at once by (for example)
>
> arrayname(x,y,:) = [1,0,0];
>
> to set the location to be pure red with 0 green and 0 blue.
>
>
> If you want to change a pixel on an existing RGB image plot directly,
> then you would do it by,
>
> arrayname = get(imagehandle, 'CData');
> arrayname(x,y,:) = [newR, newG, newB];
> set(imagehandle, 'CData', arrayname);
> --
> "Okay, buzzwords only. Two syllables, tops." -- Laurie Anderson

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