简体   繁体   中英

What can I do to enhance my image quality?

I have a 3-phase image in which I have segmented using automated thresholding (multithresh) and 'imquantize' functions. I do have lots of holes in the image without any filtering operation. However, these holes are reduced when I use a median filter although there are still quite a few of them left in-spite of the filtering. 原始图像

过滤后的分段图像

Applying the 'imfill' function from this point results in “over-filling” as observed in the red-circled part of the image shown below. FilledHoles图像

The code is as follows:

%# Read in image
I = imread(‘original_image.jpg');
figure, imshow(I),axis off, title('Original Image');

%# Filter image
I = medfilt2(I);
% figure, imshow(I), title('Median-filtered image')

%# Segment image
thresh  = multithresh(I, 2);
BW      = imquantize(I, thresh);    
figure, imshow(BW,[]),axis off, title('Segmented Image'); 

%# Fill holes
BW2     = imfill(BW,'holes');    
figure, imshow(BW2, []); title('Filled holes image');

I am just wondering if there is any better way to handle this situation. Do you think using the 'multithresh' and 'imquantize' functions are good enough for the segmentation? Can the watershed do better and is it even necessary here?

In general, please what can I do to enhance the quality of my output image?

The reason I ask is because if you scale 'imshow' of the original image you will notice that most of the black phase touches the solid (white phase). However, the automated-segmentation doesn't accurately capture this as the segmented image has rings of the intermediate (grey) phase around the solid phase. How do I also handle this?

Many thanks for your anticipated help/suggestions.

Whether your approach is good enough or not depends a lot on what you want to achieve here. For example, how smooth do the borders need to be?

To your specific question: Your quantized image has three levels, 0 (black), 1 (gray), and 2 (white). You seem to want to close the little black holes in the gray area. For this, just create a separate binary image with the gray pixels only, and then combine back into your multilevel image (which you shouldn't call BW, since the Matlab documentation uses that for binary images everywhere, and you should be consistent if you can).

% pull out the gray "channel"
grayPixels = BW==1; % will have ones everywhere there's gray, and 0 otherwise

% to close holes up to a maximum size, invert the image (holes become islands) 
% and eliminate small islands with bwareaopen
invGray = ~grayPixels;
invGray = bwareaopen(invGray,100); % closes holes up to 100pix size - adjust
grayPixels = ~invGray; % imshow to view result

% merge gray channel back in. Note we want black->gray, 
% but we don't want white->gray. 
% Since black/gray/white are 0/1/2, if we take the maximum of the gray 
% (which is 0/1) and your "BW" (which is 0/1/2), we replace 0 in BW with 1 
% wherever we have closed a hole

BW = max(BW,double(grayPixels);
imshow(BW,[]);

Similarly, you can run bwareaopen on the "black" channel to remove the white dots here and there.

You can pull the "white" channel out similarly out of BW for watershed on the large spherical particles, and you'll most likely get a pretty good result (if the white particles are what you're after).


If you want to make the thin gray borders around the white particles disappear, you could try morphological opening. Basically, you shrink the gray area by a few pixels (erosion), and then your re-grow it by a few pixels (dilation). A thin gray line will disappear completely, so there won't be anything to grow back from.

% take the gray "channel" again (after closing the small holes)
grayPixels = BW == 1;
grayPixelsOpened = imopen(grayPixels,strel('disk',3)); % play with the radius 3 to get the desired result

% everything that used to be gray and is no longer so needs to be turned black 
% in the original image
BW(grayPixels~=grayPixelsOpened) = 0;

There will be some trade-off, since the meniscus of the gray phase will no longer be as sharp. You may be able to recover somewhat with a follow-up opening of the black channel, if needed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM