- Visual Media Processing Using Matlab Beginner's Guide
- George Siogkas
- 370字
- 2021-08-06 16:38:02
Achieving color masking
Since we are into masking processes, a valid question deriving from the previous section would be: since the mask we generated is two-dimensional, how can we use it to perform masking on a three-dimensional (color) image?
The answer to the question is rather straightforward; we will actually perform separate masking in each color channel, always using the same binary mask. The tricky part of this process is that after we perform separate masking in all three channels, we will have to join the results back together to acquire the final image. A very important MATLAB function, that allows us to join matrices, is cat
. This function normally takes N + 1 inputs, where N is the number of matrices we wish to join. In the case of a color image, cat
would be called with four inputs. The first one is the dimension along which we want the concatenation to occur and the next three inputs will be the R, G, and B color channels. Let's show this with an example:
>> img = imread('my_image_color.bmp'); >> R = img(:,:,1); % store R channel in new matrix >> G = img(:,:,2); % store G channel in new matrix >> B = img(:,:,3); % store B channel in new matrix >> img_cat = cat(3,R,G,B); % Re-join color channels >> img_cat_mixed = cat(3,G,B,R); % Re-join color channels (mixed) >> subplot(1,3,1),imshow(img),title('Original Image') >> subplot(1,3,2),imshow(img_cat),title('Concatenated image') >> subplot(1,3,3),imshow(img_cat_mixed),title('Concatenated imagemixed')

This example demonstrates clearly, the way the function cat
should be used. The color channels of our image are first stored separately in three different matrices and then we join them along the three-dimension, first in their normal order and then in a mixed order (first G, then B, and then R). The first result is, as expected, identical to the original, while the second one appears chromatically distorted.
Let's now use color masking to achieve a very popular image processing effect, which is color isolation. This effect is essentially the process of converting the whole color image to grayscale, while leaving our ROI untouched, which is usually of a specific color (remember the girl with the red dress in Schindler's list?). We will try to achieve this result, using the previous image.
- Arduino入門基礎(chǔ)教程
- Windows phone 7.5 application development with F#
- 電腦維護與故障排除傻瓜書(Windows 10適用)
- Python GUI Programming:A Complete Reference Guide
- Unity 5.x Game Development Blueprints
- Manage Partitions with GParted How-to
- 筆記本電腦維修不是事兒(第2版)
- Spring Cloud微服務(wù)架構(gòu)實戰(zhàn)
- Intel Edison智能硬件開發(fā)指南:基于Yocto Project
- RISC-V處理器與片上系統(tǒng)設(shè)計:基于FPGA與云平臺的實驗教程
- 單片機技術(shù)及應(yīng)用
- 新編電腦組裝與硬件維修從入門到精通
- Python Machine Learning Blueprints
- Spring Cloud實戰(zhàn)
- 嵌入式系統(tǒng)原理及應(yīng)用:基于ARM Cortex-M4體系結(jié)構(gòu)