@Image Analyst is there a way to do this, so that the pixel value is retained on the object of interest?
How to perform OTSU thresholding while retaining the pixel information near the image
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Gucci
am 21 Apr. 2022
Bearbeitet: Gucci
am 28 Apr. 2022
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
Akzeptierte Antwort
Image Analyst
am 22 Apr. 2022
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 Kommentar
Weitere Antworten (0)
Siehe auch
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!