Clear Filters
Clear Filters

How to crop image using maximum pixel value in MATLAB

5 views (last 30 days)
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 Comments
Image Analyst
Image Analyst on 18 Aug 2022
@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.
Stephen john
Stephen john on 19 Aug 2022
@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)

Sign in to comment.

Answers (0)

Categories

Find more on Images in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!