deleting leadind and trail zeros in an image
10 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hassan Qassim
am 21 Nov. 2017
Kommentiert: Imran Riaz
am 4 Aug. 2022
Hi all I am working on enhancing a grayscal images, the first step should be cropping the image by removing lead and trail zeros (zeros rows an columns surrounding the image). i want t remove the surrounding zeros. please be advised that the cropping has be applied on zeros rows and columns that surrounding the image for different images, so i need a function or an algorithm does this cropping on different images. thanks in advance
0 Kommentare
Akzeptierte Antwort
Image Analyst
am 21 Nov. 2017
Try this:
mask = grayImage ~= 0; % Find all zeros, even those inside the image.
mask = imfill(mask, 'holes'); % Get rid of zeros inside image.
% Invert mask and get bounding box.
props = regionprops(~mask, 'BoundingBox');
% Crop image.
croppedImage = imcrop(grayImage, props.BoundingBox);
9 Kommentare
Image Analyst
am 3 Aug. 2022
@Imran Riaz I just copied the code and ran it on test1_paint.jpg and got exactly the output I posted below it. You must have changed something. Post your new image in a new question and we'll help.
Note I cropped the image - I did not mask it. I did not get a mask of "black" areas. Not sure what black pixels you want to remove but keep in mind that the image must remain rectangular. We can't have images with irregularly-shaped borders.
Imran Riaz
am 4 Aug. 2022
My image have different dimensions, I think that is the mistake. I am also attaching the image here.![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1087600/image.bmp)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1087600/image.bmp)
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Image Data Workflows finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!