Image Transformation - Histogram Shifting

15 views (last 30 days)
Sanghyeon Yi
Sanghyeon Yi on 29 Jan 2019
Edited: Walter Roberson on 11 Sep 2019
Hello,
I am new to Matlab and I am trying to transform a grayscale image with histogram shifting. The idea is like the screen shot below.
How can I set the image range between 25 and 225 and shift +50 in Matlab?
I have a code only for gray image part.
flower = imread('FlowerN.jpg');
gray = rgb2gray(flower);
%%i'm lost here..
for i=1:length(gray)
i>25 AND i<225
i = i+50
end
Thank you,
  2 Comments
Walter Roberson
Walter Roberson on 11 Sep 2019
William Stamatis comments,
This question is directly from Homework #2 in Georgia Tech's Fall 2019 ISYE 8803 Topics on High Dimensional Data Analytics class--it should be removed (I'm a fellow student in the class)
Walter Roberson
Walter Roberson on 11 Sep 2019
William:
The question cannot be from the class you note: the question was posted 8 months ago, not Fall 2019.
It is not against the rules to post questions about homework here and ask about the techniques that would be used in MATLAB to solve the technical issues. We discourage volunteers from providing complete solutions to homework; we encourage volunteers to educate the people posting the questions.
In most universities it would be plagiarism to copy an answer directly from here and use it in code. It is not, however, a problem to learn techniques from answers posted here and express them your own way.

Sign in to comment.

Answers (2)

Shunichi Kusano
Shunichi Kusano on 4 Feb 2019
If a value is added to all the pixels, the histogram shifts to the right.
MATLAB commands are:
brighter = gray + 50; % histogram shift to the right
% setting the value range between 25 to 225;
brighter(brighter > 225) = 225;
brighter(brighter < 25) = 25;
hope this helps.

Walter Roberson
Walter Roberson on 11 Sep 2019
Edited: Walter Roberson on 11 Sep 2019
This would be a good situation in which to use https://blogs.mathworks.com/steve/2008/01/28/logical-indexing/ logical indexing.
mask = YourArray meets some condition
YourArray(mask) = YourArray(mask) + something
There is another approach available using max() and min()
min( max( transformed_array, Lower_Bound), Upper_Bound)
The way this works is often confusing; I always have to hesitate and re-think the logic whenever I write this kind of code.

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!