How to change maximum Index value in MATLAB

조회 수: 6 (최근 30일)
Stephen john
Stephen john 2022년 8월 13일
댓글: Stephen john 2022년 8월 15일
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
Stephen john
Stephen john 2022년 8월 13일
@Dyuman Joshi You dont understand the above which i explain?
Stephen john
Stephen john 2022년 8월 14일
@Walter Roberson different i eleborate it more. please solve this problem

댓글을 달려면 로그인하십시오.

답변 (1개)

KALYAN ACHARJYA
KALYAN ACHARJYA 2022년 8월 14일
편집: KALYAN ACHARJYA 2022년 8월 14일
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
Stephen john
Stephen john 2022년 8월 15일
@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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by