I have three images that should have similar range of histogram is the rescaling a correct procedure?

I have three images that should have similar range of histogram is the rescaling a correct procedure or there may be better solution?
I afraid of any lost of information in my images. Is there any better idea?

Answers (3)

Hi ,
For this, you can adjust the contrast of the image with the help of “imcontrast” tool. Or you can adjust the contrast by using different functions.
Refer to the below documentations to know more about the functions and “imcontrast” tool
Hope this helps!!

3 Comments

imcontrast() only allows adjustment of the input range, but not the output range. It's only useful if the output range is the full nominal data range for the numeric class (e.g. [0 255] for uint8). If it's desired to adjust the image with range of [20 80] to an output range like [200 255] to match the other two, then imcontrast() won't work. imadjust() would work in either case.
Both tools do a simple linear transformation. Other than rounding error inherent to dealing with integer images, you shouldn't be losing information unless you select an input range that causes clipping.
I thought imadjust will change my information in a way that suprpesses the low frequency information and making the high frequency info more highlighed. Either of these two changes, I might avoid them.
Also, I used 'rescale' function, if the imcontrast in not causing information loss I'll prefer imcontrast.
imadjust(), imcontrast(), and rescale() all do similar things. They have no awareness of spatial frequency. It is strictly a linear mapping of intensity values. When both input and output ranges are specified, the transformation is equivalent to:
outpict = (outmax-outmin)*(inpict-inmin)/(inrgmax-inmin) + outmin;
The histogram will simply be translated/stretched, but the general shape of the distribution won't change unless you specify an input range that forces truncation.
Using rescale(), you can either specify the output levels alone, and the input levels are implicitly specified by the image extrema:
y = rescale(x,outmin,outmax);
or you can specify both the output and input levels:
y = rescale(x,outmin,outmax'inputmin',inmin,'inputmax',inmax);
Using imadjust(), you can specify input levels and output levels explicitly:
y = imadjust(x,[inmin inmax],[outmin outmax]);
... though imadjust expects those parameters to be normalized, and it expects the image to be correctly-scaled for its class. Rescale() does not.
Using imcontrast() only allows the adjustment of the input range, not the output range. Imcontrast() does the same thing as imadjust(), it's just less flexible. Its only unique ability is that it's a GUI tool.
If you're after something that's dependent on spatial frequency, or if you're after something that will reshape the distribution shown in the histogram, then that's a different story, and you might want to elaborate.

Sign in to comment.

It really depends on what you want to achieve. Explain why you think you want all images to have a similar histogram. It might or might not be needed, depending on what your goal is. Also explain if you just want it for a visually pleasing and comparable display, or if you want to actually change the original pixel values into something different.
Plus we need to know why they're different in the first place. Should they be the same, but, for example, your camera automatically adjusts its parameters (so they're not the same for every photo), or your lighting flickers?

4 Comments

I should combine these three images and I chose RGB as a fusion method to combine them. I applyied a high frequency bandpass filter on one channel and a low frequency bandpass filter on another channel, these two filters have equal energy and they shift my histogram to around 170 to 260 intensity values. I used my original image for the green channel so those two other images will be shown on my original image. If I do not rescale my green channel this will be my histogram:
I thought maybe if I rescale the lower part histogram I could have the original image(green channel). This is my original image or I should say the green channel:
now lets see if we rescale it and then combine it with other two images what will happen:
I expect to see the green channel underneath those blue and red spots.
Now what if I do not rescale my green channel and work with it as what it is:
I even rescaled my green channel to other ranges but in none of them, I cant see the fig2 in this comment whuch is my original B-mode image. My goal is to see those blue and red parts on the b-mode image.
Since it's just for visualizations purposes (not image analysis), I'd probably just call imadjust on all three images and then combine with cat, as long as they all have the same rough shape.
correctedImage1 = imadjust(image1);
correctedImage2 = imadjust(image2);
correctedImage3 = imadjust(image3);
% Combine into an RGB image.
compositeImage = cat(3, correctedImage1, correctedImage2, correctedImage3);
If their shapes are drastically different I'd probably scale the two darker ones, or just use imhistmatch to match the histograms. Use the brightest one as the reference to match the others to.
mean1 = mean2(image1)
mean2 = mean2(image1)
mean3 = mean2(image1)
if mean1 > mean2 && mean1 > mean3
refImage = image1;
elseif mean2 > mean1 && mean2 > mean3
refImage = image2;
else
refImage = image3;
end
correctedImage1 = imhistmatch(image1, refImage);
correctedImage2 = imhistmatch(image2, refImage);
correctedImage3 = imhistmatch(image3, refImage);
% Combine into an RGB image.
compositeImage = cat(3, correctedImage1, correctedImage2, correctedImage3);
actually my purpose is more analyzing than visualising. The next step is to calculate few parameters based on my image, and I can't do anything on the other two images which I applied my filters on.
What calculations? I can't imagine any calculations that you'd do that can't be done on the original 3 images.

Sign in to comment.

If (like @DGM mentioned) you're after something that will reshape the histograms to something custom, see my File Exchange program:
For example in the demo image below, I reshape the original histogram on the left to the silouhette of the woman as show on the right.
You can basically give any histogram you want, of any number of bins and any shape, and the process illustrated in the program will change the image such that the new histogram will have the number of bins and counts (shape) you specified.

2 Comments

That is not what I'm looking for but your algorithm is really interesting. Can you explain a little bit more about the functions of this method? what information this method will give us ?
It gives no information. It's just a fun toy with no real world use. Sure you could use it to give a perfectly flat histogram if you wanted but most people know that perfectly flat histograms, which histogram equalization functions attempt to deliver but rarely do because they're too simple and not sophistcated enough, are not useful. Histogram equalized images are not needed for image analysis as far as I've ever seen in my 40+ years of image processing, and they tend to produce harsh, awful, unnatural looking images.
It's like my Maze solving algorithm (also in my File Exchange) - no real use and just for fun.

Sign in to comment.

Products

Release

R2021a

Asked:

on 21 Aug 2022

Commented:

on 27 Aug 2022

Community Treasure Hunt

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

Start Hunting!