How to crop image using maximum pixel value in MATLAB

Hello Everyone, I hope you are doing well, I have the following Image in which I have pixel values of 255 exist on index [80,85,355,550,600]
I want to find the maximum index Value Where 255 exist for example in above 600 is the maximum value then add 50 index in it to make new index maximum value to 650
Then i want to divided the index values [80,85,355,550,600] by maximum index (650). Then multiple it 10000, to get the index value.
Let say i have index 80 where 255 (white pixel) exist. Then divide the index by maximum value (650) Which gives the value 0.1230, Then we finally multiply it by 10000 to give the index 1230. this the new index where 255 values exist. or you can say we map 80 to 1230 using white pixel values.
Now the 255 exist on index [1230, 1307,5461, 8461, 9230]
and Then we crop the image based on this values How can i do it in MATLAB

10 commentaires

Rik
Rik le 18 Août 2022
I have some difficulty following your explanation, but I suspect you can use the max function allong with the basic mathematical operators (+-*/) to get where you need to be.
Why don't you try to write the code?
@Rik I have tried but i am unable to write a code for it, Please ask question which you dont understand
Sorry, your repeated questions on the same topic have all been completely unclear to me. I will not be able to assist you in this matter.
When I looked at the responses to your other questions where you were asking about the same thing, it appeared to me as if none of the other volunteers understood your requirements either.
@Walter Roberson Which thing you don't understand? I will explain it one by one
@Walter Roberson 1. I have the image where 255 pixel values of exist on index [80,85,355,550,600]. Have you understand this step?
I will not be able to assist you in this matter.
OK, so you have this:
index=find(IM==255); % resulting in index=[80,85,355,550,600];
'I want to add 50 to this index'.
new_index=index+50;
What exactly is your question with that step? Is this what you mean?
Repeating the same text is usually not the solution. Walter has already given up, that should tell you something: your strategy is not working.
When asking a question you should have these elements:
  1. A clear description of your Matlab variables (or (if you're asking how to parse files) a short description and example file).
  2. The code you attempted to write to parse this example data. This code should be able to run in the online environment. That way you guarantee that we can reproduce what you're seeing.
  3. A clear description of what your Matlab variables should look like when the process is done. Bonus points if you clearly describe where the two differ.
@Stephen john the data is an image so what do you mean when you say "have pixel values of 255 exist on index [80,85,355,550,600]" Why are you not using (row, column) indexing?
Maybe you mean
% Find where image is 255
mask = grayImage == 255;
% Find indexes
[rows, columns] = find(mask);
% Find max row and column
maxRow = max(rows)
maxCol = max(columns)
maxOfEither = max([maxRow, maxCol]);
% Find mins
minRow = min(rows)
minCol = min(columns)
% Divide indexes by the max and multiply by 1000
rows = 1000 * rows / maxOfEither;
columns = 1000 * columns / maxOfEither;
% Crop image
grayImage = grayImage(minRow:maxRow, minCol:maxCol)
It seems kind of crazy and arbitrary. Not sure why you'd want to do this.
Perhaps if you got a native English speaker (I can tell you're not from numerous grammatical, spelling, capitalization, and punctuation mistakes) to review your post it might make more sense.
@Image Analyst we are almost near to solution just one thing remaining.
The variable rows1 are the new indexes where pixel value of 255 should exist and crop the image based on that min and max value of this new indexes
% Find where image is 255
grayImage=valueestimationimage
mask = grayImage == 255;
% Find indexes
[rows, columns] = find(mask);
% Find max row and column
maxRow = max(rows)
maxCol = max(columns)
maxOfEither = max([maxRow, maxCol]);
% Find mins
minRow = min(rows)
minCol = min(columns)
% Divide indexes by the max and multiply by 1000
rows1 = round(10000 * rows / maxRow) ;
columns1 = round(10000 * columns / maxRow) ;
% Crop image
grayImage = grayImage(minRow:maxRow, minCol:maxCol)

Connectez-vous pour commenter.

Réponses (0)

Catégories

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

Produits

Version

R2022a

Question posée :

le 18 Août 2022

Commenté :

le 19 Août 2022

Community Treasure Hunt

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

Start Hunting!

Translated by