how can i change the image contrast?
Show older comments
I need to change the image contrast,increase and decrease the contrast. only where it belongs to the region of interest.

Answers (1)
colordepth
on 13 Sep 2024
0 votes
Hi Diogo,
As per my understanding, you are looking to adjust the contrast of an image within a specific region of interest (ROI) using MATLAB. Please refer to the attached MATLAB script to achieve the desired results as shown below:

The attached script loads the image into MATLAB. The ROI is selected with “roipoly”, and its validity is checked. For contrast adjustment, “stretchlim” calculates the limits for the ROI, and “imadjust” enhances its contrast, preserving the rest of the image. The enhanced ROI is then merged back into the original image for display.
For more detailed information on contrast enhancement techniques, you can refer to the following MathWorks help page: https://www.mathworks.com/help/images/contrast-enhancement-techniques.html.
Here are documentation links of relevant MATLAB functions used in the code:
- imread - https://www.mathworks.com/help/matlab/ref/imread.html
- roipoly - https://www.mathworks.com/help/images/ref/roipoly.html
- im2double - https://www.mathworks.com/help/matlab/ref/im2double.html
- stretchlim - https://www.mathworks.com/help/images/ref/stretchlim.html
- imadjust - https://www.mathworks.com/help/images/ref/imadjust.html
- im2uint8 - https://www.mathworks.com/help/images/ref/im2uint8.html
I hope this helps!
Categories
Find more on Contrast Adjustment in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!