How to adjust brightness

I have a Dicom file and need to adjust and fix the brightness to 50% of max brightness.Thank for ans

Answers (2)

Image Analyst
Image Analyst on 14 Jan 2023
Edited: Image Analyst on 14 Jan 2023
Did you try dicomread and rescale? Not sure if you want to linearly scale all pixel values, or just clip values that go above the half brightness value. Anyway, to scale from 0 to half brightness, you can try
grayImage = dicomread(fileName);
halfMax = max(grayImage(:)) / 2;
grayImageScaled = uint8(rescale(grayImage, 0, halfMax)); % Or uint16
or scale from the original min value to half brightness like this:
grayImage = dicomread(fileName);
halfMax = max(grayImage(:)) / 2;
originalMinValue = min(grayImage(:))
grayImageScaled = uint8(rescale(grayImage, originalMinValue, halfMax)); % Or uint16
To clip values
grayImage = dicomread(fileName);
halfMax = max(grayImage(:)) / 2;
grayImageScaled = min(grayImage, halfMax);

1 Comment

DGM
DGM on 14 Jan 2023
Edited: DGM on 14 Jan 2023
Bear in mind that signed integer formats seem to be common, so if all the image data is <0, these transformations may do wacky things. The first would throw errors. The second would increase the dynamic range of the data.
Also, there's nothing guaranteeing that originalMinValue is less than halfMax, so you can expect errors, especially with a dicom file where all the image data occupies a small portion in the middle of the available range. Maybe:
% halve the range, but keep the min ??
originalMinValue = min(grayImage(:));
newMax = originalMinValue + (max(grayImage(:)) - originalMinValue) / 2;
grayImageScaled = cast(rescale(grayImage, originalMinValue, newMax),class(grayImage));
or
% scale all data by half toward black
classMinValue = intmin(class(grayImage));
newMin = classMinValue + (min(grayImage(:)) - classMinValue) / 2;
newMax = classMinValue + (max(grayImage(:)) - classMinValue) / 2;
grayImageScaled = cast(rescale(grayImage, newMin, newMax),class(grayImage));
I have no idea what OP wants either. Maybe just:
% normalize, scale by half toward black
% class doesn't matter anymore
lims = stretchlim(grayImage,0);
grayImageScaled = imadjust(grayImage,lims,[0 0.5]);

Sign in to comment.

Gulezehra
Gulezehra on 27 Apr 2023
Q1. Change the image brightness either by linear or non-linear scaling. Discuss the difference
between the 2 methods and which one leads to a better enhancement.

3 Comments

That is not a question about MATLAB.
DGM
DGM on 27 Apr 2023
Edited: DGM on 27 Apr 2023
"change the image brightness" is horribly vague
'linear scaling" has a fairly obvious meaning, but it's not the only meaning.
"non-linear scaling" is also vague -- so vague that I expect that what they actually are talking about isn't actually "brightness" adjustment, but gamma adjustment. Of course, I can't know if that's the case or if it's something else entirely. I have come to expect the assignment to simply be incomplete in its description of these specific types of tasks. Unless you can clarify, it's just a mystery.
"better" is entirely dependent on whatever "enhancement" means. Since two undescribed methods are proposed, there is no reason to assume that results should even be comparable. Is it better to enhance the number 5 by adding 1.9, or by raising it to the power of 1.2? It's a nonsense question. You either want addition or you don't.
Since every part of these two sentences is either vague or subjective, the answer is meaningless without clarification.
Please bear in mind that I know you weren't the one who wrote the assignment text; that said, if the assignment text is the only communication you offer, there really isn't anything anyone can do but respond to what you've provided.
In the meantime, here are a number of ways to adjust "brightness". Many of these methods also support some form of nonlinear adjustment. Also mentioned are different linear adjustment techniques which may explicitly be described as "brightness" adjustments, or which may otherwise manipulate image brightness.
Suppose I take a picture of my back yard at night. My camera has a limit on how long it can keep the shutter open, so even at maximum shutter duration, the image is underexposed. To make the objects of interest more visible, I am going to want to increase the image brightness.
Suppose I take a picture of my back yard on a sunny day. If my camera is pointed in an unfortunate direction, even if my camera can shutter down and speed up enough, the objects of interest may be overexposed from the sun. To make the objects of interest more visible, I am going to want to decrease brightness.
Now, if you wrote your program to "change the image brightnes" in exactly one way within each of "linear" or "non-linear", is that program going to be able to correct both of those images without further guideance from the user? If I was taking pictures of the sky instead of my back yard, is the variety of enhancement that is appropriate for emphasizing stars in the night image going to be the same as the variety of enhancement to deal nicely with the cloud formations? And when I do the clouds, is it "better" to use the algorithm that tends to enhance contrast, or is it "better" to use the algorithm that tends to reduce glare?
I think it doubtful that you could arrive at a conclusion about which of the two kinds of image brightness changing leads to "better" enhancement. "Better" for what purpose?
You might want to process the exact same image twice in order to emphasize different information in the image. No one algorithm can possibly guess correctly which image aspect you are interested in right now.

Sign in to comment.

Asked:

on 14 Jan 2023

Edited:

DGM
on 27 Apr 2023

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!