To refine figure 1 using logarithmic and power transformations in Matlab, you can use the following code:
main.m571 chars19 lines
In the code above, we first read the input image using the imread
function. We then apply the logarithmic transformation by first converting the image to double precision using the double
function, adding 1 to avoid the logarithm of 0, taking the logarithm using the log
function, scaling the result to the range [0, 255] using the uint8
function, and finally displaying the result using the imshow
function.
Next, we apply the power transformation using the equation s = c * r^gamma
, where s
is the output pixel value, r
is the input pixel value, c
is a constant, and gamma
is a parameter to choose. In this example, we set c = 1
and gamma = 0.5
, but you can experiment with different values to achieve the desired transformation. Again, we scale the result to the range [0, 255] using the uint8
function and display the result using the imshow
function.
Finally, we display all three images (original, logarithmic transformation, and power transformation) side by side using the subplot
function and the title
function to label each plot accordingly.
gistlibby LogSnag