3
$\begingroup$

i would like to calculate difference of two images. Then, histogram of difference of two images. So I can plot a histogram but I am not sure whether it is true or not? Also, I am not sure about what should be second parameter of built-in histogramfunction.

My two images are original_result and output_image. And difference of two image is image_of_dif. my result:

image_of_dif = double(original_result) - double(output_image);
figure; histogram(image_of_dif(:), 511);

enter image description here

$\endgroup$
1
$\begingroup$

Let us suppose that images are coded on uint8, hence integers in $[0,\ldots,255]$. For the difference image, values can range from $0-255$ or $255-0$, the maximum span. So I would keep the negative differences by computing the histogram over all $511=255-(-255)+1$ integers in $[-255,\ldots,255]$.

| improve this answer | |
$\endgroup$
  • 1
    $\begingroup$ i changed second parameter of histogram to 511. is it okay now? $\endgroup$ – beyblade41 Dec 17 '19 at 13:51
  • $\begingroup$ This looks ok to me. This way, you get an histogram of all possible values in the difference. $\endgroup$ – Laurent Duval Dec 20 '19 at 19:24
1
$\begingroup$

In your second line, casting with uint8() will change a negative value to 0. Avoid casting or change to another type that supports negative values.

| improve this answer | |
$\endgroup$
  • $\begingroup$ i changed my code. is it ok now? $\endgroup$ – beyblade41 Dec 17 '19 at 8:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.