How can I replace value in array by graphic file(pattern)?
显示 更早的评论
I have a picture (matrix containing only values 1,2,3 and 4). I would like to replace each value by different pattern stored in graphic file,for example I would like to replace each value 1 by line pattern, 2 by cross pattern, etc. in order to obtain visual effect of the picture, thanks to different intensity of the pattern.
For example I have pattern like this:
x = [0 0.5 1 1.5 2 2.5 3 3.5 5];
y = [0 2.5 -2.5 2.5 -2.5 2.5 -2.5 2.5 0];
plot(x,y,'k','LineWidth',4);

and I would like to replace every 4 by this pattern.
I would be grateful for any help :)
2 个评论
Image Analyst
2016-5-2
What do you mean by "picture" and "matrix"? It looks like you're talking about line plots, not pictures/images.
采纳的回答
更多回答(2 个)
1. Load your four patterns into a cell array however you want, e.g:
patterns = cell(1, 4);
for patidx = 1:4
patterns{patidx} = imread(fullfile('C:\somewhere\', sprintf('pattern%d.png', patidx)));
end
2. If need be, resize all the patterns so they're the same size. All patterns need to be the same size for the next step to work.
desiredsize = [10 10];
patterns = cellfun(@(pat) imresize(pat, desiredsize), patterns, 'UniformOutput', false);
3. Use simple indexing and cell2mat to create your final image:
finalimage = cell2mat(patterns(grayimage)); %where grayimage is your image with 4 levels
imshow(finalimage);
2 个评论
buki
2016-5-7
Guillaume
2016-5-7
When reporting an error, give the entire error message, particularly the part that tells you which line and which instruction is causing the error. Without that information, it's anybody's guess at what the problem is.
A complete guess: the problem is with patterns(grayimage) and that would be because there are more than 4 grey levels in your image.
Image Analyst
2016-5-3
1 个投票
It looks like that's a raw (not demosaiced) image. Is it?
One way would be to just blur the image a lot.
类别
在 帮助中心 和 File Exchange 中查找有关 Blocked Images 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



