- Read and Convert the Image: Start by reading your image and converting it to a suitable color space if necessary.
- Apply Color Quantization: Use the ‘rgb2ind’ function to reduce the number of colors in the image, which can give it a painterly look. Adjust the number of colors to control the level of abstraction.
- Display the Result: Show the original and modified images for comparison. Consider combining this with other filters, such as blurring or edge detection, to enhance the impressionist effect.
How do I use quantization to achieve the impressionist of my picture?
4 次查看(过去 30 天)
显示 更早的评论
I have been tasked with quantisizing an image to recreate the image but with an impressionist filter. Below is my source code, I've been trying to change the range values but I've yet to get the desired result. What do I need to do?
level1 = 50;
level2 = 150;
level3 = 200;
% For every color
for i = 1:3
tmp = im(:,:,i);
if i == 1
% Red quantization
tmp(tmp < level1) = 50;
tmp(tmp > level1 & tmp < level2) = 100;
tmp(tmp > level2 & tmp < level3) = 150;
elseif i == 2
% Green quantization
tmp(tmp < level1) = 50;
tmp(tmp > level1 & tmp < level2) = 120;
tmp(tmp > level2 & tmp < level3) = 150;
elseif i == 3
% Blue quantization
tmp(tmp < level1) = 50;
tmp(tmp > level1 & tmp < level2) = 100;
tmp(tmp > level2 & tmp < level3) = 150;
end
quantim(:,:,i) = tmp;
end
0 个评论
回答(1 个)
Subhajyoti
2024-8-30
编辑:Subhajyoti
2024-8-30
You can use the ‘imquantize’ function in MATLAB to quantize any image using specified quantization levels and output values. To achieve an impressionist effect, you can follow these steps:
By experimenting with the number of colours and additional image processing techniques, you can create a unique impressionistic style for your images.Here is a basic example of how you might use it:
% Read in the picture of green mountains
im = imread('mountains.jpg');
% Generate thresholds for seven levels from the entire RGB image.
threshRGB = multithresh(im,7);
% Generate thresholds for each plane of the RGB image.
threshForPlanes = zeros(3,7);
for i = 1:3
threshForPlanes(i,:) = multithresh(im(:,:,i),7);
end
% Process the entire image with the set of threshold values computed from entire image.
value = [0 threshRGB(2:end) 255];
quantRGB = imquantize(im, threshRGB, value);
% Process each RGB plane separately using the threshold vector computed from the given plane.
% Quantize each RGB plane using threshold vector generated for that plane.
quantPlane = zeros(size(im));
for i = 1:3
value = [0 threshForPlanes(i,2:end) 255];
quantPlane(:,:,i) = imquantize(im(:,:,i),threshForPlanes(i,:),value);
end
quantPlane = uint8(quantPlane);
% Display both posterized images and note the visual differences in the two thresholding schemes.
montage({quantRGB,quantPlane})
title("Full RGB Image Quantization vs. Plane-by-Plane Quantization")
% To compare the results, calculate the number of unique RGB pixel vectors in each output image.
% Note: the plane-by-plane thresholding scheme yields about 23% more colors than the
% full RGB image scheme.
dim = size(quantRGB);
quantRGBmx3 = reshape(quantRGB,prod(dim(1:2)),3);
quantPlanemx3 = reshape(quantPlane,prod(dim(1:2)),3);
colorsRGB = unique(quantRGBmx3,"rows");
disp("Unique colors in RGB image: "+length(colorsRGB));
colorsPlane = unique(quantPlanemx3,"rows");
disp("Unique colors in plane-by-plane image: "+length(colorsPlane));
To learn more about the 'imquantize' function, you might find it helpful to visit the MATLAB Documentation through this link:
Also, you can open the MATLAB Command Window and enter:
>> doc imquantize
This will open directly the documentation page for the ‘imquantize’ function.
I hope this helps
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Convert Image Type 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!