Tuesday, 2 June 2009

Nice walk and converting an Image's colour profile / colour space using the Imagick extension for php

This morning I went out for a walk, it was very nice and warm and sunny. I went down the old railway line towards Lubenham, and quite a bit of the track was covered in buttercups, purple clover and forget-me-nots. I saw a small blur butterfly that I took a lot of photos of, and one or two skippers, which always flew off when I was about to press the shutter.

Further on down the railway line towards Lubenham, where it became a proper track that tractors could go down again, there weren't so many buttercups, but there was lots of seeding/flowering grass.

On the section of unfarmed field at the end of the track, there were also lots of buttercups there, and a few butterflies I think. I walked up to the field near Thorpe Lubenham Hall, that had lots of buttercups in it, but they and the grass were all relatively short (kept down by grazing cattle I presume). As my memory card was almost full and I wanted to be back home in time for lunch, I didn't go into that field, but walked back along the road past the church and school, then down the road towards the main road.

Then I walked back to Harborough along the main road and over the hill. I did see a few white butterflies (large whites I think) and one other large butterfly (a peacock I think), but they never seemed to stop, unlike the small blue butterfly and skipper (which was also small) I had seen.

When I got home I copied the pics to my comp and went on the pinternet a bit until lunch time.

After lunch I did a backup and went on Animal Crossing, then my CD-I arrived! I spent the afternoon setting up the CD-I and playing on Animal Crossing. Setting the CD-I took quite a while as it didn't come with any instructions, and the TV aerial adapter box thing was quite weird, having one lead for the video, and a 2.5mm plug that I didn't know where it should go. There was a 2.5mm socket on the back of the CD-I, but it was labeled 'DC out', so I didn't want to plug the cable in there in case it would blow something up.

After googling for CD-I manual, I found a copy of the CD-I manual, actually in the support section of the Phillips website. Good that they keep support information for old products. Reading that I saw that actually the 2.5mm jack should be plugged in the DC-out socket, and that it also provides sound to the TV through that connection as well. The power socket for the CD-I was quite weird as well, looked like a LAN socket.

With that done, I got the CD-I working on Moccles TV, but the picture was constantly jumping up and down by a small amount. I didn't really notice it while playing though. I'll have to try the CD-I on a different TV to make sure the problem isn't with the CD-I. I don't think it will be since the seller said they'd tested it all and it worked okay.

Also in the afternoon, I went in the garden, when I didn't have my camera I saw a red damselfly and a bee that seemed to be patrolling a patch of the garden. But when I did have my camera I didn't see much.

In the evening I watched Springwatch and did some work on my website.

First I wanted to make it so that when my image was downsized, it would look as good as the same image downsized and sharpened in photoshop. I played around with the blur parameter of the Imagick::resizeImage function/method, and found that for my test image (a fly on some grass), a value of between 0.7 and 0.8 gave the best results (the lower the value, the sharper the image). My current resize command looks like: $thumb->resizeImage(1024, 720, Imagick::FILTER_LANCZOS, 0.78, true);

However, this still didn't seem to look as good as the image resized with photoshop and then given a small amount of smart sharpening. The ImageMagick resized version had a small amount of moire in the fly's compound eye, and didn't look quite as sharp either. But good enough for the moment as far as I'm concerned.

Next I wanted to find a way to get ImageMagick to convert my image to sRGB. Using google I found Creating Image Thumbnails using PHP and ImageMagick, which sets the colourspace using the commandline 'convert' command. But I wanted to use something from the Imagick PHP extension to do the conversion if possible, as it should be faster, and keep all my ImageMagick code using the php extension rather than some using the php extension and some using calls to the shell.

Searching on the Imagick php extension page in the php manual for 'color', I found there was a Imagick::setImageColorspace method/function. But when I used this, it didn't seem to do anything, and when I inspected the created image in photoshop, it's profile was still Adobe RGB 1998.

Doing more googling I found Converting JPEG colorspace (Adobe RGB to sRGB) on linux and also some other page that was useful I think, but I've closed it and don;t know what it was. Anyway, the point made on the page I'd closed was that it's the Image color profile that needs to be set, rather than the Image color space.

So, searching on the Imagick php extension page in the php manual for 'profile', I found Imagick::setImageProfile. Unfortunately this page doesn't have any notes on how to use it, but luckily the page for Imagick::profileImage does.

So after reading the user contributed notes for Imagick::profileImage, I googled to find the sRGB ICC profiles I could download and use for Imagick to use. I found 3 different versions available on the International Color Consortium website. Unfortunately they had 3 different versions - version 4, 2.1 black scaled, 2.1 not black scaled. Photoshop just seemed to use 2.1 (maybe not black scaled?). Anyway, I tried out all 3 profiles. They saved okay, as when I viewed the image in photoshop, I could see what profile I had chosen. However, the image didn't seem to be converted to sRGB as the colours were still drab. It was like what you get when choose 'Assign profile' in photoshop rather than 'Convert to profile'.

So then I tried Imagick::profileImage, which was the one with the user notes about converting the image's colour profile. And that seemed to work how I wanted, and convert the profile. The colours weren't quite the same as the image converted to sRGB in photoshop, so I'll have to play around with the different sRGB profiles tomorrow. It also seems that the ICC profile embedded in the image is much larger than the one photoshop embeds. Again, I'll have to look at that tomorrow.

The weather today was sunny and warm, with no clouds in the morning, and then getting a bit cloudy in the afternoon.

Food
Breakfast: Orange maramalade toast sandwich; cup o' tea.
Lunch: Peppered ham with iceberg lettuce sandwich; large satsuma; ½ grated cheddar cheese sandwich; caramel Rocky; cup o' tea.
Dinner: Salmon pastry thing; green beans; cauliflower; broccoli; potatoes. Pudding was some yoghurt and a bit of chocolate muffin. Coffee. Cadbury's caramel.
Supper: Hot chocolate; milk chocolate digestive; fly biscuit.

No comments: