Jpegs are in my understanding, store rectangular sections of the image ( If I remember stored coefficients), so I guess you could do edge detection as the compressed data represents some sort of semblance to what is encoded, but
GIF's are just LWZ encoded chunks. I don't see any way you could determine what's in it without decompressing.