How to change maximum Index value in MATLAB

7 views (last 30 days)
Hello everyone i hope you are doing well.
I have the following image in which white pixel value exist 35,40,45,55
  • I want to find the maximum pixel (index) for example in above 55 is the maximum pixel (index) then add 50 pixel in to to make new maximum value to 105
  • Then i want to divided the each pixel value with the maximum value(105). Then map the value to 10000 e.g multiple new pixel value with 10000 so it will map between 1 to 10000
as you can see i have 1's in logical array in position 35,40,45,50,55
I want to shift the values by 50 for examples 33 to 88 and 55 to 105.
Then i will divided the index value by new maximum value which is 105.
for example 35/105=0.333 which then multiple by 10000 which gives the results 3333 Now the 1's start should be in the index 3333
same for remaining value
for example 55 is maximum value then 55/105=0.5238 which is multiple by 10000 which is 5238 is the maximum value where 1's exist.
  4 Comments
Stephen john
Stephen john on 13 Aug 2022
@Dyuman Joshi You dont understand the above which i explain?
Stephen john
Stephen john on 14 Aug 2022
@Walter Roberson different i eleborate it more. please solve this problem

Sign in to comment.

Answers (1)

KALYAN ACHARJYA
KALYAN ACHARJYA on 14 Aug 2022
Edited: KALYAN ACHARJYA on 14 Aug 2022
I re-read the question again-
  • I want to find the maximum pixel (index) for example in above 55 is the maximum pixel (index) then add 50 pixel in to to make new maximum value to 105
Lets say data is an 2D gray image, int8, having maximum pixel value is 255 (considering pixel range 0-255)
%Lets add 50 on those pixel having more than 55 pixel value
im_data=uint8(data>50)*55;
result_im=data+im_data;
Imp Note: Have you noticed that the maximum number of pixels in a Unit 8 image cannot exceed 255? On the other hand you can do the same approach assuming the pixel values to be a pure matrix and do all the calculations (avoid unit 8 conversion).
Let's say data variable is double data type
%Lets add 50 on those pixel having more that 55
data=double(data);
im_data=double(data>50)*55;
result_im=data+im_data;
Let's say maximum value is 305, code is as follows
>> max(result_im(:))
  • Then i want to divided the each pixel value with the maximum value(105). Then map the value to 10000 e.g multiple new pixel value with 10000 so it will map between 1 to 10000
max_val=max(result_im(:));
result_mat=result_im/max_val;
% Map the values in between 1 to 10000
result=interp1([min(result_mat),min(result_mat)],[1,10000],result_mat);
Hope it helps!
Kalyan
  1 Comment
Stephen john
Stephen john on 15 Aug 2022
@KALYAN ACHARJYA , Here is my 2D array image is attached, but the main problem you have changed the pixel values, but does not change the index value, where 255 exist it is replace by 305, but index is still 33:37

Sign in to comment.

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!