conversion from double to logical=lose of information?

조회 수: 7 (최근 30일)
Lightisthenight
Lightisthenight 2019년 1월 16일
댓글: Lightisthenight 2019년 1월 17일
I have an image stack of about 1000 images and i want to segment every single image with the bwareafilt() method and afterwards substract some filtered images. As you can see I did this in a for loop. My im_mod here is my binarized vessel filtered image and has the dimension 256x256x1000 double
for i=0:options.ImageAmount-1
bwspatter1(:,:,i+1) = bwareafilt(im_mod1(:,:,i+1),5,'smallest');
bwspatter1(:,:,i+1) = bwareafilt(im_mod2(:,:,i+1),5,'smallest');
torchspatter_image1(:,:,i+1)= double(ves1(:,:,i+1))- double(meanpicture1bw_mod);
torchspatter_image2(:,:,i+1)= double(ves2(:,:,i+1))- double(meanpicture2bw_mod);
torchonly1(:,:,i+1) = double(torchspatter_image1(:,:,i+1)) - double(bwspatter1(:,:,i+1));
torchonly2(:,:,i+1) = double(torchspatter_image2(:,:,i+1)) - double(bwspatter2(:,:,i+1));
torchonlymod1(:,:,i+1) = imresize(torchonly1(:,:,i+1), [800 1280]);
torchonlymod2(:,:,i+1) = imresize(torchonly2(:,:,i+1), [800 1280]);
torch1(:,:,i+1) =imbinarize(torchonlymod1(:,:,i+1));
torch2(:,:,i+1) =imbinarize(torchonlymod2(:,:,i+1));
end
I got an error message when running this code. It says that expected input number in my method bwareafilt() should be logical instead of double. I want to convert this with the logical() method in Matlab which converts any nonzero element of my matrix to logical 1 (true) and zeros are converted to logical 0 (false).
My question is if i do that and process the images after that and calculate their centroids do i loose information in the image ?
I tried to do it before with a single image and i didn't need to convert to logical , so I'm uncertain about it.

채택된 답변

Walter Roberson
Walter Roberson 2019년 1월 16일
What you do is threshold the image through some appropriate method (perhaps imbinarize()) to produce a logical mask. If your im_mod1 and im_mod2 are currently bilevel (0 and non-zero) then logical() would do.
You would then bwareafilt() the logical values. The result would be a logical mask that you can use to extract information from your original image.
In computation, logical values can be combined with doubles as if the logical values were double(0) and double(1). They cannot be directly combined with integer classes, but you can uint8() the logical to get uint8(0) and uint8(1)
regionprops() on a binary image would give the centroids per connected component. You might potentially want to multiply the binary by the grayscale image in order to segment based on grayscale intensity, or you might potentially want to replicate the mask to 3D and multiply by the original color image in order to then proceed to segmentation based upon color.
  댓글 수: 3
Walter Roberson
Walter Roberson 2019년 1월 16일
bwspatter1(:,:,i+1) = bwareafilt( logical(im_mod1(:,:,i+1)), 5, 'smallest');
bwspatter2(:,:,i+1) = bwareafilt( logical(im_mod2(:,:,i+1)), 5, 'smallest');
torchonly1(:,:,i+1) = torchspatter_image1(:,:,i+1) .* cast(bwspatter1(:,:,i+1), 'like', torchspatter_image1);
torchonly2(:,:,i+1) = torchspatter_image2(:,:,i+1) .* cast(bwspatter2(:,:,i+1), 'like', torchspatter_image2);
If you know ahead of time that torchspatter_image* are uint8 then you can simplify to
torchonly1(:,:,i+1) = torchspatter_image1(:,:,i+1) .* uint8(bwspatter1(:,:,i+1));
torchonly2(:,:,i+1) = torchspatter_image2(:,:,i+1) .* uint8(bwspatter2(:,:,i+1));
Lightisthenight
Lightisthenight 2019년 1월 17일
Thank you! You helped me a lot.

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

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by