The issue you're experiencing with getting a black image could be due to several factors in implementation of the heat equation for image deblurring.
- Conductivity Coefficient k: In given code, “k” is being assigned the number of colour channels of the image. This is incorrect for image deblurring. Define “k” as a small positive constant that controls the rate of diffusion (e.g., k = 0.1).
- Ensure that the pixel values remain within a valid range (0 to 255) during the iterations. If the values exceed this range, they might cause the image to appear completely black or white.
- When using “imagesc”, the scaling might affect the display. Ensure that the image data is correctly scaled for visualization.
Revised code with above mentioned consideration will be:
u0=imread(‘path_to_your_image.jpeg');
u_xx = u(:, [2:n n]) - 2*u + u(:, [1 1:n-1]);
u_yy = u([2:m m], :) - 2*u + u([1 1:m-1], :);
u = u + k*dt*(u_xx + u_yy);
title(['t = ', num2str(t)]);
imwrite(uint8(u), 'clockdeblur.tiff', 'TIFF');
The output for the following code with sample input is given below:
For better understanding of “imagesc”, refer to the documentation, which you can access by running the following command in MATLAB command window:
- web(fullfile(docroot, "matlab/ref/imagesc.html"))
Hope that helps!