In this example, we will try to set the values of the pixels in the top-left corner of our image to {R, G, B} = {128, 128, 128} and the values of the pixels in the bottom-right corner to {R, G, B} = {255, 0, 0}. To see the difference, we will try to accomplish our goal using indexing. Let's start:
First off, we load our image and keep a copy:
>> img_color = imread('my_image_color.bmp'); >> img_color_orig = img_color;
Then, we will try to set our top-left corner to the specified values:
>> img_color(1:50,1:50,:) = 128;
Now, if we want to do the same for the bottom-right corner, we should modify our approach. Not all color channels should be set to the same value, thus each color channel must be changed separately:
>> img_color(end-49:end,end-49:end,1) = 255; >> img_color(end-49:end,end-49:end,2) = 0; >> img_color(end-49:end,end-49:end,3) = 0;
Finally, we will show our results:
>> subplot(1,2,1),imshow...