필터 지우기
필터 지우기

How to perform OTSU thresholding while retaining the pixel information near the image

조회 수: 3 (최근 30일)
The mistake with my code is when I calculate the centroid -
The matrix I are centroiding: bin_im = im2bw(B, temp) returns a binary image. This is an image where values are either 0 or 1, which is discarding all the information about which pixels are brighter than others near the peak....
How can I still use the graythresh method for OTSU thresholding, and still retain the information about the pixels that are brighter than others near the peak of the bead?? I.E. not use a binary image for the centroid calculation
a sample dataset is included with 3 images, and my code is below:
clc;
clear;
close all;
load('my_mat_file.mat');
%% Center Container
center=zeros(2,size(ims,3));
%% Image loop
for x=1:3
A=ims(:,:,x);
%% Size of Matrix A
[r,c]=size(A);
%% Otsu thresholding
B=im2gray(A);
temp=graythresh(B);
bin_im=im2bw(B,temp);
%% centroid calculation
tot_mass = sum(bin_im(:));
[ii,jj] = ndgrid(1:size(bin_im,1),1:size(bin_im,2));
R = sum(ii(:).*bin_im(:))/tot_mass;
C = sum(jj(:).*bin_im(:))/tot_mass;
center(:,x) = [C;R];
end

채택된 답변

Image Analyst
Image Analyst 2022년 4월 22일
You can use the gray scale image to determine the weighted centroid -- the centroid of the binary blobs but weighted by the brightness of the pixels in the gray scale image.
props = regionprops(bin_im, B, 'WeightedCentroid', 'Centroid');
% Extract from structure into matrices
xy = vertcat(props.Centroid); % Centroid of binary blobs.
xyWeighted = vertcat(props.WeightedCentroid); % Centroid of binary blobs but weeighted by gray level.
  댓글 수: 1
Gucci
Gucci 2022년 4월 28일
편집: Gucci 2022년 4월 28일
Thank you this works
Also how can I display the gray level image in a figure?

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

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by