Is it possible to resize a region in a grayscale image?

1 回表示 (過去 30 日間)
Tiffany Mao
Tiffany Mao 2017 年 6 月 27 日
編集済み: Gopichandh Danala 2017 年 6 月 28 日
Is it possible to resize a white blob in a grayscale image without changing anything else? If so, how can I do so? I am trying to resize the largest blob while keeping the size of the other regions the same.

採用された回答

Gopichandh Danala
Gopichandh Danala 2017 年 6 月 28 日
編集済み: Gopichandh Danala 2017 年 6 月 28 日
The steps for this is to extract the largest Blob, resize it as per requirement, again map it back to the original image to increase the size of it.
img = imread('blobDilate.jpg');
img = rgb2gray(img);
img(img < 50) = 0;
[rows, cols] = size(img);
figure, imshow(img), title('Original Image');
% Get the max Blob
largestBlob = bwareafilt(logical(img), 1);
figure, imshow(largestBlob)
% increase the size [+50, +50]of the Blob and remove the added rows, cols
resizeImg = imresize(largestBlob, [rows + 50, cols + 50]); % You can change this according your requirement
% remove added rows, cols
removeRows = [1:25, size(resizeImg,1)-24:size(resizeImg,1)];
removeCols = [1:25, size(resizeImg,2)-24:size(resizeImg,2)];
resizeImg(removeRows,:) = [];
resizeImg(:,removeCols) = [];
figure, imshow(resizeImg)
% New Blob Area
props = regionprops(logical(resizeImg),'Area');
resizedBlobArea = [props.Area];
fprintf('%s %d\n', 'newResizedBlobArea: ', resizedBlobArea)
% final Image
finalImg = logical(img + uint8(resizeImg));
figure, imshow(finalImg), title('Largest Blob resized Image')
  2 件のコメント
Image Analyst
Image Analyst 2017 年 6 月 28 日
You know, you can get the largest blob simply by doing
largestBlob = bwareafilt(binaryImage, 1);
instead of all that stuff with regionprops(). largestBlob will be a binary image of the same size as the original but with only 1 blob, the largest, in it.
Gopichandh Danala
Gopichandh Danala 2017 年 6 月 28 日
編集済み: Gopichandh Danala 2017 年 6 月 28 日
Oh thanks Image Analyst, I didn't knew it before. I updated the above answer

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with Image Processing Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by