Playing with images and MATLAB
I know I said I wouldn’t use MATLAB again but Octave instead. I lied. This afternoon I was a little bit bored and began playing with images and tiny scripts (almost one-liners).
First of all, let me introduce you my cat. It’s called Trasto, a catalan word that means piece of junk, although in catalan it’s not as offensive as in English
These are just a few quick experiments. The leit motiv of all is reducing colors of the image (although not much).
Playing with flat structuring elements
First of all I played with a disk structuring element. The intention was to make flat homogenous regions of color.
This is my first try:
cn=4096;
cs=colorcube(cn);
t=ind2rgb(imerode(rgb2ind(i,cs),strel('disk',3)),cs);
t looks like this:
To smooth the image a little bit while presenving homogenous regions I used median filtering:
t2(:,:,1)=medfilt2(t(:,:,1),[5 5]); t2(:,:,2)=medfilt2(t(:,:,2),[5 5]); t2(:,:,3)=medfilt2(t(:,:,3),[5 5]);
This is how t2 looks like:
Now the same image using 1024 colors. Keep in mind that palette of 1024 colors is made using colorcube, which doesn’t use image data to choose the values, so the resulting image has much less than 1024 colors. We could use some adaptative process to choose them if we wanted to, and we’d probably see that adjacents colors in the cat would be more similar from each other than they are now (and probably would happen just the opposite in other places).
And what about non-flat structuring elements?
Perhaps the image has too much detail to seek homogeneous colors. We could try to use non-flat structuring elements, like ball, and see what we get. For instance, let’s use ball with radius 2 and height 1.
cn=1024;
cs=colorcube(cn);
t=ind2rgb(imerode(rgb2ind(i,cs),strel('ball',2,1)),cs);
We apply median filtering, as before:
Using greater height values we can get funny things (for instance radius 5 and height 5) due to saturation:
And with median filtering:
Texturing the image using shaped structuring elements
What happens if we use a cross as a structuring element?
cs=2048; t=ind2rgb(imerode(rgb2ind(i,colorcube(cs)), [1,0,0,0,1; 0,1,0,1,0; 0,0,1,0,0; 0,1,0,1,0; 1,0,0,0,1]), colorcube(cs));
Reducing the number of colors the effect is much more visible:
We obviously don’t use median filtering here because we would eliminate the texturing effect of the crosses.
If we use horizontal lines as structuring elements,
cs=256; t=ind2rgb(imerode(rgb2ind(i,colorcube(cs)), [1,1,1,1,1,1,1]), colorcube(cs));
, we get:
Since my cat is called Trasto I’ll use T-shaped structuring elements:
cs=256; t=ind2rgb(imerode(rgb2ind(i,colorcube(cs)), [0,0,1,1,1,0,0; 0,0,0,1,0,0,0; 0,0,0,1,0,0,0; 0,0,0,1,0,0,0; 0,0,0,1,0,0,0; 1,0,0,1,0,0,1; 1,1,1,1,1,1,1]), colorcube(cs));
Note: I didn’t realize when I saved all the images to JPEG format using imwrite that MATLAB has the default quality setting for JPEG very low. So you’ll see the “water” effect of JPEG in images. This is specially true for last images, crosses, lines and T should be all homogeneous.
