필터 지우기
필터 지우기

select ROI, threshold it and remove small objects - App designer

조회 수: 4 (최근 30일)
In the attached app designer file I select a ROI, threshold it and remove small objects from binary image. I have encounter two problems: 1) the threshold silder value is not dynamic, 2) the remove object does not work properly (I get a black square).
Any idea why and how it can be solved?

채택된 답변

Abolfazl Chaman Motlagh
Abolfazl Chaman Motlagh 2022년 3월 3일
about the first problem:
you overwrite the app.Icrop on app.I every time the slider changes. so after first time, it goes completely black. you should keep app.I and for representing the image create a local image for ploting. replace the below code with the respected part of yours for this solution. or you could have a backup for app.I, or you could create a new variable. if at the end you want to save the image it's better to have another variable for changed image.
function otsuthresholdSliderValueChanged(app, event)
value = app.otsuthresholdSlider.Value;
app.Icrop = app.I(app.row1 : app.row2, app.col1 : app.col2, :);
app.Itemp = imbinarize(app.Icrop,value)*255;
app.Icrop = app.Itemp;
I_local = app.I;
I_local(app.row1 : app.row2, app.col1 : app.col2, :) = repmat(app.Itemp, [1 1 size(app.I,3)]);
imshow(I_local,'Parent', app.ImageAxes)
end
for second problem:
the function bwareaopen is a function which act on binary images and remove connected components with less than specific number of pixel. the word remove here means replace the pixels with 0. your image ('peppers.png') is not a binary image. but still your usage of this function is wrong. the all ROI you select become 0 after using this function.
  댓글 수: 2
Jane Bat
Jane Bat 2022년 3월 4일
편집: Jane Bat 2022년 3월 4일
Thanks, the image (app.Icrop = app.Itemp;) transfered to the bwareaopen is already binary. Do I miss something as it should have worked. Is it possible that the error is due to this line app.I(app.row1 : app.row2, app.col1 : app.col2, :) = repmat(app.Itemp, [1 1 size(app.I,3)]);?
Abolfazl Chaman Motlagh
Abolfazl Chaman Motlagh 2022년 3월 4일
the binarization you refering is missing before function bwareaopen operate because you multiply it's result by 255 in otsuthresholdSliderValueChanged.
i attach my code to this comment. i think it will do everything you need. here's what i add and change about your code:
  1. Add I_bin to properties of app. this is variable for result of thresholding that goes to remove process.
  2. in otsuthresholdSliderValueChanged i remove 255 coefficients from app.Itemp , instead use uint8(255*app.Itemp) in ROI replacement line.
  3. in RemoveButtonPushed i created a new variable for local image called I_local that is the image which it's ROI substitudes with image processed with bwareaopen.
  4. like in otsuthresholdSliderValueChanged the result of bwareaopen is binary (0&1) for using in other images i multiply it's result by 255 and make it uint8 then replace the ROI.
it works perfectly for me, tell me if it's done.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Processing and Computer Vision에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by