How to remove values beyond threshold from certain label?

1 Ansicht (letzte 30 Tage)
Abhi Ove
Abhi Ove am 8 Feb. 2018
Bearbeitet: Abhi Ove am 8 Feb. 2018
Dear all,
I have a set of values intValues (data set attached at bottom). From the values I create a binary mask and label each region.
bulkBinaryMask = intValues > 0;
bulkBinaryLabel = bwlabel(bulkBinaryMask);
From "Region 2" I would like to remove any values <-0.05 and >+0.05.
I know how to remove values for whole data set as such:
intValues(intValues<-0.1)= 0.
I was wondering how do I remove values within each region?
To expand on this question for future, lets say, I want to replace the 9th and last values of the region 1 to be 0. How do I do that?
Many thanks in advance and really appreciate your help.
intValues = [0;0;0;0;0;0;0;0;0;0;0;0;0.26244465;0.29007468;0.26653862;0.29302722;0.26668695;0.26518479;0.26084769;0.28639266;0.26425231;0.25237250;0.26585105;0.29383880;0.25984868;0.28605866;0.28393352;0.23753427;0.21833633;0.21159969;0.19674303;0.19256258;0.14822936;0.15898322;0.16137893;0.11557713;0.096215844;0.12425362;0.11965461;0.12414602;0.14914773;0.17779414;0.16764416;0.10261737;0.097361661;0.26717466;0;0;0;0;0;0;0;-0.091555580;-0.014126119;-0.0075604324;-0.010243786;-0.015728250;0.014402754;0.0061065373;-0.034150224;0.033243932;-0.025414338;0.0021870080;-0.017752288;-0.0042569139;0.0010967045;-0.0025044910;-0.0091931168;-0.00098206359;-0.022899218;-0.0093692830;-0.011437733;-0.0084309950;-2.7552773e-05;-0.0043535922;0.0090775713;0.036743760;0.23081724;0;0;0;0;0;0;0;0;0.10118896;0.16281490;0.15751003;0.12994391;0.15854512;0.17712460;0.24465595;0.17683943;0.11180082;0.14216836;0.14462484;0.10606941;0.14113182;0.19906932;0.16165967;0.21997970;0.31712520;0.30911356;0.31779054;0.29921058;0.32097855;0.30999324;0.30381167;0.29537085;0.28719103;0.32213023;0.33997473;0.31646192;0.31416368;0.33734962;0.32147244;0.33623534;0.31780452;0;0;0;0;0;0;0;0];
  2 Kommentare
Image Analyst
Image Analyst am 8 Feb. 2018
So as the final result, bo you want a new binary image with only region 2 in there but a new region 2 which does not include any values in that range in the original image? Note that removing original pixels in that range might possibly split region 2 into 2 or more separated regions depending on where the values to be removed lie.
Abhi Ove
Abhi Ove am 8 Feb. 2018
Bearbeitet: Abhi Ove am 8 Feb. 2018
Hi, I would still need the final matrix to maintain its original size. I can easily eliminate my values beyond my threshold as such when I do not need the original matrix.
%
tempIndices = find(intValues(bulkBinaryLabel==2) => 0.05 );
tempIndices = find(intValues(bulkBinaryLabel==2) <= -0.05 );
%
However with this data, I only need to replace values with 0 on certain region at certain position in the matrix. I am OK if more regions are created as long as I can eliminate values that are beyond my experimental range. I hope this helps.
Please do have a look at my code below if you have time. I would really appreciate a better way of doing things!

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Abhi Ove
Abhi Ove am 8 Feb. 2018
I have found a very elaborate way of achieving my goals (please see the codes attached). However I find it hard to believe that, it is not possible to do this easily. Please do suggest an alternative if possible. I personally do not like these sort of over-the-top codes if an elegant solution exists.
for ii = 1 : size(intValues,2) % for row of intValues data this will carry out the same tasks
tempData = intValues(bulkBinaryLabel == 2, ii); % temporarily isolate the data with label 2
% remove values above threshold
rows = find(tempData >= noiseThreshold); % find rows with values below threshold
if isempty(rows) % if no such values exists, move on
else
for jj = 1:size(rows,1) % else for each rows of values...
idx = find (intValues(:,ii) == tempData(rows (jj) ) ); % find index of that value in full data set
intValues(idx, ii) = 0; % replace that value with 0.
end
end
% same as above, but for lower noise threshold.
% remove values below threshold
rows = find(tempData <= -noiseThreshold);
if isempty(rows)
else
for jj = 1:size(rows,1)
idx = find (intValues(:,ii) == tempData(rows (jj) ) );
intValues(idx, ii) = 0;
end
end
end

Weitere Antworten (1)

Birdman
Birdman am 8 Feb. 2018
I would like to remove any values <-0.05 and >+0.05
To do this at one line, type
intValues=intValues(intValues>=-0.05 & intValues<=0.05);
  1 Kommentar
Abhi Ove
Abhi Ove am 8 Feb. 2018
Hi, with this code I only get the values within that region as output. I am trying to
1) Maintain the shape of the original matrix 2) replace certain values in each region as I specify.
Many thanks for the answer.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by