- Visual Media Processing Using Matlab Beginner's Guide
- George Siogkas
- 298字
- 2021-08-06 16:38:01
Time for action – repainting two areas in a color image
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(img_color_orig);title('Original Image') >> subplot(1,2,2),imshow(img_color);title('Altered Image')

What just happened?
We just managed to play with the colors of a color image. We used the indexing in exactly the same way you already knew, to turn an area to gray (with all color channels set to 128) and then we repeated the process for each color channel in another area to set its pixels to red. A useful observation is that three identical values in all color channels denote a shade of gray. This fact is rather intuitive, as in Chapter 1, Basic Image Manipulations, we saw that imtool
represented the pixels of grayscale images as triplets of identical values. The process must be slightly altered when we want a color other than gray. This is why, in our example, we changed the values in each channel separately.
- 零點(diǎn)起飛學(xué)Xilinx FPG
- Learning SQL Server Reporting Services 2012
- 用“芯”探核:龍芯派開發(fā)實(shí)戰(zhàn)
- Applied Unsupervised Learning with R
- BeagleBone By Example
- INSTANT Wijmo Widgets How-to
- 電腦組裝、維護(hù)、維修全能一本通(全彩版)
- 硬件產(chǎn)品經(jīng)理成長(zhǎng)手記(全彩)
- 筆記本電腦維修實(shí)踐教程
- 單片機(jī)技術(shù)及應(yīng)用
- WebGL Hotshot
- 新編電腦組裝與硬件維修從入門到精通
- Building Machine Learning Systems with Python
- Hands-On One-shot Learning with Python
- Exceptional C++:47個(gè)C++工程難題、編程問題和解決方案(中文版)