Today I want to show you a handy little function, imsplit, for splitting color images into their components.
Also, for no reason other than WOW, I want to show one of the images just released by the James Webb Space Telescope program (home page, flickr galleries).
url = "https://live.staticflickr.com/65535/52211883534_7fe30b9955_o_d.png";
text(size(rgb,2),size(rgb,1),"Image credits: NASA, ESA, CSA, and STScl",...
VerticalAlignment = "top",...
HorizontalAlignment = "right")
Anyway, back to imsplit. Long-time readers have seen me use code like this to split up color images (sometimes RGB, sometimes $ L^* a^* b^* $) into component images:
L = lab(:,:,1);
a = lab(:,:,2);
b = lab(:,:,3);
See, for example, the posts about two-dimensional histograms (23-Dec-2010) and segmenting images in $ (a^*,b^*) $ space (04-Feb-2011).
That code is not hard to write, but now I've become fond of using imsplit instead, just because it is a bit more compact, without sacrificing understandability. The function imsplit, introduced in release R2018b, is used this way:
url = "https://blogs.mathworks.com/images/steve/2010/mms.jpg";
That's it, really. There's nothing more to it. Give it a try the next time you need to do this; it'll save you 2.7183 seconds.
Before I go, let's look at that Webb telescope image one more time, just because.
To leave a comment, please click here to sign in to your MathWorks Account or create a new one.