Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^5: Perl Image Analysis

by lparsons42 (Novice)
on Oct 06, 2006 at 18:58 UTC ( [id://576742]=note: print w/replies, xml ) Need Help??


in reply to Re^4: Perl Image Analysis
in thread Perl Image Analysis

Ok, I used that to determine the intensity of a single pixel in greyscale. However, when I tried a simple test of it, I got unexpected results.
I made a test image, that was 24 pixels wide by 12 pixels tall. This is a jpeg that I made in kolourpaint and set to greyscale. It has a white background and I used only black color on it. I made two boxes on this image, which are each 8x with 2 white pixels all the way around and 4 white pixels in the center between the two boxes.
The truly curious can see this da vinci - quality 834 byte jpeg at this site
However, when I analyze this file, I get varied results for what should not be varied intensities. Specifically, the spots (5,5) and (5,17) should both be intensity 0 (since they are 100% black). However, this is not the case. Instead, (5,5) registers 15 and (5,17) registers 0.
Any insight as to why this is would be great!

Replies are listed 'Best First'.
Re^6: Perl Image Analysis
by BrowserUk (Patriarch) on Oct 06, 2006 at 20:05 UTC

    I loaded the image using Opera and used it's zoom function to blow the image up 1000%. It is then fairly obvious that the "white" area immediately surrounding the black squares is full of slightly off-white pixels, including #f2f2f2, #f1f1f1, #ededed, #f6f6f6, #f5f5f5, etc. This is probably an artifact of the JPEG 'lossy' compression system, though it could also be an artifact of the drawing program you used to constuct it.

    Update: Actually, looking at it again (looking at my lcd from an oblique angle), the black isn't entirely black either. bThere are several pixels in both squares that are variously #0f0f0f, #030303, #0c0c0c etc.

    Redo your image using the non-lossy .png or .tiff formats. If the artifacts go away, it was the JPEG compression biting you. If they don't, it is your drawing program that may be attempting to antialias something. Either look for a configuration option to turn that off or use a 'dumb' graphics editor (like mspaint.exe) that doesn't attempt to do anything clever :) (The had to be some advantage to paint didn't there :)

    Also, be wary of what program you use to zoom the image. For example, Ifranview will resample the image as you zoom it unless you explicitly turn that option (view->properties->view->Use resample) off. This results in the edges of the squares getting antialiased, and the corners getting rounded as the image is zoomed.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Yes, I see now what you mean. I didn't expect that jpg conversion would hurt a greyscale image like that.
      I then retried this using a tiff file instead. I found that the GD library can read jpgs and pretty much only jpgs. It errors out on PNG, GIF, and TIFF.
      Looks like I'm going back to using the Imager module so I can read TIFFs.
      Thanks again all!

        GD can certainly read .png & .gif. I'm not sure about tiff.

        For .gifs you need a fairly recent version (post the expiry of the .gif patent), but I use GD to create and manipulate .pngs all the time, and going back at least 4 years.

        What are the errors you are getting when you try to load a .png?


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
Re^6: Perl Image Analysis
by grep (Monsignor) on Oct 06, 2006 at 20:22 UTC
    Don't forget about (lossy) jpeg compression. You'd be better off using GIF or TIFF for this experiment.
    identify -verbose  identify -verbose artificial_black_n_white.jpg


    grep
    One dead unjugged rabbit fish later

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://576742]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-03-19 08:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found