conversion from double to logical=lose of information?
16 ビュー (過去 30 日間)
古いコメントを表示
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.
0 件のコメント
採用された回答
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
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));
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!