Segment and crop photos to JPEG files.

3 views (last 30 days)
I am a total newbie at this and am attempting to use Matlab R2019b Trial Version to segment images from JPEG files. Here is the situation: I have numerous JPEG "photo of photos" files - in other words, someone scanned a whole bunch of photo album pages that each contain 3 (or more) photos on each to JPEG files (one photo album page per file). What I want is an automated cropping procedure whereby the 3 (or more) photos on the photo album page are segmented out and ultimately stored as 3 separate JPEGs. The photo album page has a matte black background; most photos have a white border. One additional challenge: sometimes the 3 photos overlap each other a bit. I have gone through the segmentation tutorials and have successfully created masks but I don't know how apply the mask to the original photo (need to do??) and to then save each cropped photo to a separate JPEG file. I have attached a sample starting JPEG.
  1 Comment
KALYAN ACHARJYA
KALYAN ACHARJYA on 23 Nov 2019
Ohh it may possible, it will take time to test and then answered, let's see.

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 23 Nov 2019
In your loop over all images, call a function called ExtractImages(). In that function you need to do something like
function outputImageCellArray = ExtractImages(rgbImage)
% Convert to grayscale with rgb2gray()
grayImage = rgb2gray(rgbImage);
% Threshold at some brightness just above the gray background you are using
mask = grayImage > 128;
% Call bwareaopen() or bwareafilt() to keep only blobs bigger than a certain size.
mask = bwareafilt(mask, [10000, inf]);
% Fill any holes.
mask = imfill(mask, 'holes');
% Call regionprops() and get the bounding boxes.
props = regionprops(mask, 'BoundingBox');
% Loop over all bounding boxes extracting the images.
for k = 1 : length(props)
thisBB = props(k).BoundingBox;
outputImageCellArray{k} = imcrop(rgbImage, thisBB);
end

More Answers (0)

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!