Decompose image into the sum of two images

3 ビュー (過去 30 日間)
Jenalyn Palacios
Jenalyn Palacios 2020 年 3 月 26 日
コメント済み: Jenalyn Palacios 2020 年 3 月 26 日
I have a black image with different sized white squares all over the image. If we let A denote this image, "decompose" A as the sum of two images A=A1+A2, such that A1 contains the larger sqares and A2 contains the smaller squares. Your code should display seperately A1 and A2.
This is my code so far. but i know its completely wrong. Can someone please help me with this!!
A=imread('small-squares.tif');
se = strel('square',7);
eroded = imerode(A,se);
figure
subplot (1,2,1), imshow(A), title('original')
subplot (1,2,2), imshow(eroded)

採用された回答

Image Analyst
Image Analyst 2020 年 3 月 26 日
Hint: you need to segment the image (perhaps by thresholding),
allSquares = grayImage > 0;
or from imbinarize(). Then use regionprops to find out the size of all the squares and what threshold you want to use to distinguish small squares from big ones.
props = regionprops(.......
Then use bwareafilt() to create masks for smallSquareMask and bigSquareMask.
smallSquareMask = bwareafilt(............
bigSquareMask = bwareafilt(............
Then mask the gray image twice
% Mask the image using bsxfun() function to multiply the mask by each channel individually.
maskedRgbImage = bsxfun(@times, rgbImage, cast(mask, 'like', rgbImage));
to get two masked grayscale images or RGB images. When you add those two together you'll get the original image.
  1 件のコメント
Jenalyn Palacios
Jenalyn Palacios 2020 年 3 月 26 日
Thank you thank you!!

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

その他の回答 (1 件)

Guillaume
Guillaume 2020 年 3 月 26 日
I don't see how your code even attempt to answer your assignment.
Which of the image processing function would you use to detect objects in an image?
Which other image processing function would you use to know the size of such objects once detected?
Once you know which pixel belong to which object (from the first function) and the size of such object, it's easy to copy them to the correct image.
I'm afraid I won't give you any more hint than that. It's not a particularly difficult task.

カテゴリ

Help Center および File ExchangeImage Segmentation and Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by