How to crop image using maximum pixel value in MATLAB
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
Image Analyst
2022-8-18
@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.
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!