How to Split image based on a blue line in image - so i want to split image into 2 and the cut should be where a blue line is in the image.
3 次查看(过去 30 天)
显示 更早的评论
I would like code that splits image into 2 - one with everything below blue line and other with everything above line then i can do my code. But i dont know how to do that
Or code that allows me to change all pixels to transparent below or above blue line.
Or code that just works out average pixel intensity below the blue line and average pixel intensity above blue line from image which is what i will be doing in the end.
Would appreciate if you could help.
1 个评论
DGM
2022-3-16
What is to be done in places where there are obvious gaps/jumps in the data? Is that to be stitched together? Are those unrelated segments to be discarded?
Is it meaningful to take the average value of pixels representing grid lines and other traces?
回答(2 个)
DGM
2022-3-16
编辑:DGM
2022-3-16
Here's this. I'm going to assume that gaps represent a transition between relevant and irrelevant data. If that's not the case, then you'll have to decide what it means and probably resort to manual patching and accept the fact that the gaps will skew your mean.
A = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/928519/image.png');
Ahsv = rgb2hsv(A);
% HSV thresholds
th = [0.45 0.54;
0.30 1.00;
0.30 1.00];
% basic color-based mask generation
th = permute(th,[3 2 1]);
mask = all(Ahsv >= th(1,1,:) & Ahsv <= th(1,2,:),3);
mask = bwareaopen(mask,10);
mask = imfill(mask,'holes');
imshow(mask)
% crop off everything but the main segment
mask = bwareafilt(mask,1);
segmentmask = any(mask,1);
A = A(:,segmentmask,:);
mask = mask(:,segmentmask);
% segment the background
CC = bwconncomp(~mask);
% get the mean color of each region
meancolor = zeros(CC.NumObjects,3);
for k = 1:CC.NumObjects
for c = 1:3
thischan = A(:,:,c);
meancolor(k,c) = mean(thischan(CC.PixelIdxList{k}));
end
end
meancolor
0 个评论
yanqi liu
2022-3-16
img = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/928519/image.png');
jmg = rgb2lab(img);
s = imcomplement(mat2gray(jmg(:,:,2)));
b = im2bw(s, 0.7);
b = bwareafilt(b,1);
b1 = b; b1(end,:) = 1;
b1(:,1) = 1; b1(:,end) = 1;
b1 = logical(b1);
b1 = imclose(b1, strel('line', 100, 90));
b1 = imclose(b1, strel('line', 5, 0));
b2 = ~b1;
img1 = img .* uint8(cat(3, b1, b1, b1));
img2 = img .* uint8(cat(3, b2, b2, b2));
figure; imshow(img1, []);
figure; imshow(img2, []);
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!