Eliminating the Border Around a Generated Image

1 回表示 (過去 30 日間)
Sarah
Sarah 2018 年 8 月 27 日
コメント済み: Sarah 2018 年 8 月 27 日
I am creating images using the rectangle() function with various line and space sizes. I attached an example image to this question. I want to eliminate the border of white that surrounds the black rectangles. (It affects my pixel count calculations.) Currently, I am just using the imcrop() function, but the cropping dimensions have to change according to the line and space sizes. Is there a more efficient way than imcrop()?

採用された回答

jonas
jonas 2018 年 8 月 27 日
編集済み: jonas 2018 年 8 月 27 日
There is a function that will do this for you in one step, but I forgot what it's called. Here's a primitive solution for you!
[y1,x1]=find(BW==0,1,'first')
[y2,x2]=find(BW==0,1,'last')
BW2=BW(y1:y2,x1:x2)
imshow(BW2)
Basically you find the upper left and bottom right corners, and then crop a rectangle between those.
  5 件のコメント
Image Analyst
Image Analyst 2018 年 8 月 27 日
Yep. 3 color channels - it's RGB. Try this first
BW = BW(:, :, 2); % Take green channel.
or else, if you want to keep it as a color image, do this:
BW2 = BW(y1:y2, x1:x2, :)
Sarah
Sarah 2018 年 8 月 27 日
Excellent, thank you. Now it all works well.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImages についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by