MATLAB Answers

How to add a boundary into a image for saving

18 ビュー (過去 30 日間)
R G 2017 年 6 月 27 日
コメント済み: Image Analyst 2019 年 7 月 19 日
As the title, I have an image A and boundary B = bwboundaries(C) if I wanna show it, I can use imshow (A); hold on; visboundaries(B,'Color',''); if I use save button. the image I save don't have the same resolution as my source image so what should I do now?

  0 件のコメント



Gopichandh Danala
Gopichandh Danala 2017 年 6 月 28 日
The problem may just be with either the way you save or with way you used bwboundaries. I wrote some sample code using bwperim to get boundary image of a region then save it in png format to save lossless
img = imread('peppers.png');
figure, imshow(img);
% getting a segment
position = wait(h);
figure,imshow(region); title('Segmented Region');
% use bwperim rather than bwboundaries to get an Image of boundary.
boundImg = uint8(bwperim(rgb2gray(region),4));
boundImg(boundImg ~=0) = max(img(:));
figure, imshow(img + boundImg)
% save image without loosing information..
imwrite(img + boundImg, 'writeImg.png');
% check
read = imread('writeImg.png');
figure, imshow(read)
isequal(read, img + boundImg)

  8 件のコメント

表示 5 件の古いコメント
Gopichandh Danala
Gopichandh Danala 2017 年 6 月 28 日
no problem
Warid Islam
Warid Islam 2019 年 7 月 19 日
Hi Gopichandh,
Is it possible to crop the image specified by the boundary above?
Image Analyst
Image Analyst 2019 年 7 月 19 日
Of course. Use find() on region or position, then use max() and min() to find the max and min rows and columns, then use indexing to extract the cropped region.
[rows, columns] = find(region);
row1 = min(rows);
row2 = max(rows);
col1 = min(columns);
col2 = max(columns);
croppedImage = img(row1:row2, col1:col2, :);


その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by