why the following code do this to make binary a image
2 次查看(过去 30 天)
显示 更早的评论
I have a code to binaryce a image, but I dont undertand why rest the red chanel and blue chanel and then say if the rest are less than 1 is equal to 0.... if its greater than 1 is equal to 1. Why the code make the rest between RM and BM? what benefits have this? why simply binarice a image
for i = 1:length(Filelist)
CFileName = Filelist(i).name;
filename = CFileName;
IM = imread(CFileName);
IM = imgaussfilt(IM,1.5); % The use of the filter depends on the value standard deviation, i.e. 0.9
IM = double(IM);
RM = IM(:,:,1);
GM = IM(:,:,2);
BM = IM(:,:,3);
mask = IM(:,:,1);
RBD = RM-BM;
GBD = GM-BM;
RGD = RM-GM;
mask(RBD<1) = 0;
% mask(GBD<60) = 0;
% mask(RGD<0) = 0;
mask(mask>1) = 1;
% cd ..
cd Binary_images
% h=figure(1);
% imshow(mask);
imwrite(mask,sprintf(filename));
cd ..
0 个评论
回答(1 个)
KALYAN ACHARJYA
2020-11-20
编辑:KALYAN ACHARJYA
2020-11-20
There are several methods to obtain the resulting image as a logical or binary image. That does not mean, why does it not follow direct imbinirize? The main issue is in what context the code has been written?
What is binary image?
Any image with logical data (0 or 1), consider as binary image, supoose you have an image with the following-
mat =
0.2785 0.9706 0.4218 0.0357 0.7431
0.5469 0.9572 0.9157 0.8491 0.3922
0.9575 0.4854 0.7922 0.9340 0.6555
0.9649 0.8003 0.9595 0.6787 0.1712
0.1576 0.1419 0.6557 0.7577 0.7060
Now, in this partcular case, you may get binary image in various way-
bw1=imbinarize(mat);
or
bw2=mat>0.4
Why they do in such way?
Before proceeding to the logical operation in the attached code, it performs channel extraction, then applies a threshold mask to get the result value 0 or 1. The resulting mask here is not a binary image (please verify the data type in the workspace). Just having 0 or 1 in the element does not mean that the image is binary, if the image is binary, you can see the logical data type mentioned in the workspace.
"Why the code is like this"?
I have no answer, in which context the code is written, I have no clue, but it seems that it just implements the basic operation.
Is tehre any sense of doing it this way?
It can only be confimred, after test the with their original image. I have no clue as to which code is written, it is better to ask the person who wrote the code.
Still you did not get the issue, please call me, I will give you my 2 minutes to explain it, as I have seen since yesterday, you are continnusly editing the question several times to get attention from its members.
Good Wishes!
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!