How to change a pixel value of a RGB

12 views (last 30 days)
Bong Kyu Choung
Bong Kyu Choung on 19 Sep 2016
Answered: Image Analyst on 19 Sep 2016
I am trying to change a pixel value of a RGB image with the property '512*512*3 double'. I tried like gray scale images below
imagename(100,100) = [0.1,0.1,0.1];
or
imagename(100,100,1) = 1.0;
iamgename(100,100,2) = 0.1;
imagename(100,100,3) = 0.1;
The first one results more than original dimensions.. I have spent hours and so tried now.
The second one results redish image......
I'd be very appreciate with any help. Thanks.

Answers (2)

José-Luis
José-Luis on 19 Sep 2016
imagename(100,100,:) = [0.1, 0.1, 0.1];
Please read about indexing.

Image Analyst
Image Analyst on 19 Sep 2016
Not sure what you're asking, but as you found out, the second way is correct. A color RGB image is a 3-D array with one color channel for red, one for green, and one for blue. Each color channel by itself is a 2-D image but when combined into an RGB image it becomes a 3-D array which takes 3 indexes, (row, column, colorChannelValue). To set a particular row and column to a value you have to use : and specify all three values
rgbImage(row, column, :) = [redValue, greenValue, blueValue];
Or you can do it one color channel at a time.
rgbImage(row, column, 1) = redValue;
rgbImage(row, column, 2) = greenValue;
rgbImage(row, column, 3) = blueValue;
But you can't do it like you did at first.

Categories

Find more on Modify Image Colors in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!