This post is modified from our previous blog, with our own permission. 🙂
We received some queries on the image pixels, which make us think that sometimes we might just go too far. So let’s back to the basic for this post and coming few posts. (we might be adding some application specified application from time to time, any ideas on what you wish to see, feel free to post at the comments).
Yes, one more thing we would like to say, we do apologize on missing some posts last few weeks, due to we were focusing on the preparation of IPCV 1.2, as well as putting our public training on IPCV up and running. Thanks for your understanding.
Again, we will use our favorite baboon.png, feel free to us any RGB image for your testing. If you insist to have the same image with ours, just right click and download the image above at full size or find it from the IPCV images folder. (size: 512x512x3)
How to highlight certain portion on an image?
The basic concept of highlighting part of an image is “Overwriting Pixel Value” on the image. We start from the basic idea on how to mask portion of image with blank sub-image (black color sub-image).
S = imread('baboon.png'); Sblack = uint8(zeros(50,50,3)); S2 = S; S2(1:50,1:50,:) = Sblack; subplot(121); imshow(S); subplot(122); imshow(S2);
How to create a color mask rather than black color mask?
Since the 3 layers of image matrix represent RGB layers of the image, we can create the red color mask using following command, and the results are shown as shown.
Sred = Sblack; Sred(:,:,1)=255; S2 = S; S2(1:50,1:50,:) = Sred; subplot(121); imshow(S); subplot(122); imshow(S2);
How to create a transparent mask?
Simple enough, just play with the values R value, and perform the image addition rather than overwriting the value as follow:
Sred = Sblack; S2 = S; S2(1:50,1:50,1) = 255; subplot(121); imshow(S); subplot(122); imshow(S2);
Finally, how to create an outline for the image?
Adding outline for the image is simply adding extra pixels to all sides of the images, this is how to add black outline.
linelength = 30; Sblack = uint8(zeros(512+linelength*2,512+linelength*2,3)); S2 = Sblack; S2((1+linelength):($-linelength),(1+linelength):($-linelength),:)=S; subplot(121); imshow(S); subplot(122); imshow(S2);
Both images looks the same size, but actually they have been resized to have a better visual effect. We could check the size of the images with the following commands:
512. 512. 3.
572. 572. 3.
That’s all for this week, see you in the next post!