How to modified maximum pixel value in logical array

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
I have find the maximum and minimum pixel value as 35 and 55
idx = find(mask);
row1 = min(idx);
row2 = max(idx);
How can i do it in matlab

5 commentaires

dpb
dpb le 12 Août 2022
Look at optional second output from min and max and then ind2sub to convert to row,column.
The image is 10000x1000, with a set of thick lines near the top of the image. The lines occupy rows 33:57.
load mask.mat
%imshow(mask(30:60,:))
nzrows = find(any(mask,2));
mnrow = min(nzrows)
mnrow = 33
mxrow = max(nzrows)
mxrow = 57
It's not really clear whether you're trying to find the positions of the pixels or just the y-centers of each line.
It's not clear what the position of the lines has to do with the pixel value. Are the pixels just being colored by their position, or are the entire line objects colored by the position of their y-centers? Given that you're mapping to an output space of 1:10000, are you trying to do a geometric transformation of the objects instead?
@DGM you can say the position of line on y-center. which has the min value 33 and max 57.
The entire object colur by position on y-centers.
I want to change the position
  • I want to find the maximum position for example in above 55 is the position then add 50 pixel in to to make new maximum position to 105
  • Then i want to divided the each pixel value with the position(105). Then map the value to 10000 e.g multiple new position value with 10000 so it will map between 1 to 10000
@DGM 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.

Connectez-vous pour commenter.

Réponses (1)

DGM
DGM le 13 Août 2022
Modifié(e) : DGM le 13 Août 2022
I'm going to post this as a tentative answer. I doubt my interpretation of your intent is wholly correct, but it's probably correct enough to demonstrate inroads to a satisfactory answer.
% get mask array
load mask.mat
% get y-centers for each blob
CC = bwconncomp(mask,4); % picking 4-connectivity is important here
S = regionprops(CC,'centroid');
ycenters = vertcat(S.Centroid);
ycenters = ycenters(:,2); % y-center of each blob
% get input and output range
inrange = [min(ycenters) max(ycenters)+50]; % [35 105]
outrange = [1 10000];
% get rescaled values for each blob
blobvals = (outrange(2)-outrange(1))*(ycenters-inrange(1))/(inrange(2)-inrange(1))+outrange(1);
% recolor image according to calculated blob values
outpict = zeros(size(mask)); % preallocate
for b = 1:CC.NumObjects
outpict(CC.PixelIdxList{b}) = blobvals(b);
end
% [35 105] is scaled to [1 10000]
% but bear in mind that 55 is smaller than 105
pxrange = [min(nonzeros(outpict(:))) max(nonzeros(outpict(:)))]
pxrange = 1×2
1.0e+03 * 0.0010 2.8579

1 commentaire

@DGM I think I can not say it correctly.
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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Images dans Centre d'aide et File Exchange

Produits

Version

R2022a

Question posée :

le 12 Août 2022

Commenté :

le 13 Août 2022

Community Treasure Hunt

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

Start Hunting!

Translated by