How can I replace value in array by graphic file(pattern)?
Mostra commenti meno recenti
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 Commenti
Image Analyst
il 2 Mag 2016
What do you mean by "picture" and "matrix"? It looks like you're talking about line plots, not pictures/images.
Risposta accettata
Più risposte (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 Commenti
buki
il 7 Mag 2016
Guillaume
il 7 Mag 2016
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
il 3 Mag 2016
1 voto
It looks like that's a raw (not demosaiced) image. Is it?
One way would be to just blur the image a lot.
2 Commenti
buki
il 7 Mag 2016
Image Analyst
il 7 Mag 2016
If it's a raw image you should demosiac it.
Categorie
Scopri di più su Blocked Images in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



