Changing image background from black to white

3 ビュー (過去 30 日間)
Mona Al-Kharraz
Mona Al-Kharraz 2020 年 4 月 7 日
コメント済み: Shafiullah Soomro 2020 年 10 月 4 日
Hi,
I have chromosomes image and I segmented this image to multiple chromosome images (46 images). But after segmentation I got these images in black background. How I can changes the balck background to white?

採用された回答

Ilian
Ilian 2020 年 4 月 7 日
You can try using connected components. With relatively simple problems this could work:
img_original = imread('image.jpeg'); % load image
img_pad = padarray(img_original,[10 10], 0); % pad to simplify cc
threshold = 35;
img_pad(img_pad<threshold) = 0; % threshold image
img_pad(img_pad>=threshold) = 1;
img_inverted = 1-img_pad; % invert image
CC = bwconncomp(img_inverted,4); % find connected components
pixelList = []; % list of pixel in background
for i = 1:length(CC.PixelIdxList)
% discard small components that are part of the chromosome
if length(CC.PixelIdxList{1,i}) > 1000
pixelList = [pixelList cell2mat(CC.PixelIdxList(i))'] ;
end
end
mask = zeros(size(img_pad)); % create a mask
mask(pixelList) = 1;
mask = mask(11:end-10,11:end-10); % remove padding
img_corrected = img_original;
img_corrected(logical(mask)) = 255; % set background pixels to white
% PLOT
figure;
subplot(1,4,1); imagesc(img_original); axis image; colormap gray
subplot(1,4,2); imagesc(img_inverted); axis image; colormap gray
subplot(1,4,3); imagesc(mask); axis image; colormap gray
subplot(1,4,4); imagesc(img_corrected); axis image; colormap gray
  2 件のコメント
Mona Al-Kharraz
Mona Al-Kharraz 2020 年 4 月 7 日
I don't know how I can thank you. You help me many thanks
Shafiullah Soomro
Shafiullah Soomro 2020 年 10 月 4 日
how can i do same for lung dataset images.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeRed についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by