开发者

Minor image differences in image manipulation program

I've implemented a method that takes an input image and flips it around a vertical line through the center and saves it to an output image file. So whats on the left becomes on the right and vice versa. The image looks great and looks like it flipped perfectly. However, we are given the actual flipped image file that its supposed to look like, and I used the diff utility in terminal to compare the two, and it states that there are indeed differences. Using a program called Kaliedoscope, I was able to find out the difference:ther开发者_开发技巧e are a handful of pixels that for some reason are colored differently than they should be. Not sure why it is. My code doesnt even manipulate RGB values.


What image format did you save as? If you used a lossy compression, such as JPEG, then the image colours will always be slightly different, as they have been re-compressed. You should use a non-lossy format such as PNG.

You should also not use 'diff' to look at images. I don't know what Kaleidoscope is, but the ImageMagick 'compare' utility is good for looking at the difference between two images. 'diff' will almost always tell you there is a difference between two images, even if they are identical and you used a non-lossy format, due to the fact that when you recompressed it, it might use a different compression technique.

Also, you say you were given the flipped image file (assuming this is a homework thing). In that case, it's possible that the person who generated that file made the mistake (e.g., using a lossy compression). I would not worry about minor pixel differences in that case.


If your function works well, it should be its own inverse (as a necessary condition, although not enough to prove correctness).

Check if

a == flipleft(flipleft(a)) 

What if you trusted third party testing software has a bug?

HTH!

Edit

Also check the vertical center of the image, to be sure that when the number of horizontal pixels is even you are swapping the two in the middle.


There doesn't seem to be anything obviously wrong with your code.

Since you have a reference image, you can tell the precise pixel positions where there is a difference. I suggest that you step through your program with a debugger (gdb if you're a Linux user, or Visual Studio if that's what floats your boat) and put breakpoints in the inner loop of your code at the problem positions. Using those breakpoints, look for the first point in the program where the problem manifests itself. This will help you find the cause.

Working with smaller images (something that you can print to the command-line at each iteration, for example 8x8 pixels) may save you some time when debugging.

It may be good to post images -- your result and the expected reference.


Modify your code so that you read the input image into an Image and then write it into an output file (without reversal) and compare the input file to the output file.

If they do not match then either the file->Image->file process is corrupting the data (perhaps with a pixel member that is the wrong size, leading to roundoff or use of uninitialized memory) or the comparator (e.g. Kaleidoscope) is wrong, and you can test by just copying the input file and comparing.

If they do match then either your reversal procedure is wrong (which seems unlikely) or the reference file (which the output "is supposed to look like") is wrong, and you can test by altering the code to read in the reference file as well, and report the first disagreement-- that is, construct three Images, Before (read from the input file), After (which will be written to the output file) and Reference (which was read from the reference file), then iterate over x and y, comparing After(x,y) to Reference(x,y). As soon as you find a disagreement, see which one matches Before(width-x-1, y); if Reference matches then your reversal routine is wrong, and if After matches then the reference file is wrong (and you can point to a pixel that proves it).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜