十字绣到Matlab [英] Cross Stitch to Matlab

查看:184
本文介绍了十字绣到Matlab的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的女朋友说她可能会开始做一些
正如你所看到的,网页中颜色的选择是不同的,实际上它更有意义,即使没有真正的色彩图也能给人很好的感觉。



经过大量的努力,我相信我需要改变和实施两件主要的事情。



1.-我不相信100 %DCMRGB值。我通过电子邮件向公司寻求有关他们调色板的更多信息。



2.-亮度,对比度,色调和饱和度值对输出有很大影响。



如何使用Matlab修改所需图像中的这4个值(如网页中所示)?









DMC2RGB文件:(如果需要,我可以将其粘贴到此处)



http://pastebin.com/qixUgnvy



DCM颜色托盘:



解决方案

好的,这是一个普遍的建议,虽然我没有设法得到很好的结果然而。



1)首先使用 rgb2ind 将原始图像缩小为合理数量的颜色 nodither ,仅指定颜色数量(不是使用的地图)。

  [ I_ind,old_map] = rgb2ind(I,64,'nodither); 

您可以尝试适合给定图像的颜色数量而不会丢失太多细节。基本上你想要先弄清楚你想要多少种独特的颜色(看到你正在交叉缝合输出,你不需要一堆只用于每个三针的颜色)。



2)转换两个映射( rgb2ind 的输出和从dcm加载到rgb文件的映射)到一个合适的色彩空间(我使用HSV,因为我感觉很懒, L * a * b 可能更好)。



3)通过检查哪些索引颜色具有最多像素来选择颜色,选择最接近的颜色,然后从候选列表中删除该颜色,以便最终得到64或其他

 %使用直方图和排序 - 首先为最常见的值指定颜色
[plist pbins] = hist(I_ind(:),0:63);
[plist_sorted,sort_ind] = sort(plist,'descend');

%old_map = rbg2ind的输出
%new_map =我们即将在同一颜色空间中生成
%dcm_map =(副本!)的新颜色
new_map = zeros(size(old_map));

%从最常见到最不常见的循环,如果我们使用它,则从dcm地图中删除颜色。 $ = b $ b,n = 1:sort_ind
D = pdist2(old_map(n,:),dcm_map);
m = find(D == min(D),1,'first');
new_map(n,:) = dcm_map(m,:);
dcm_map(m,:) = [];
结束

我使用了你曾经用过的图像。因为它来自 rgb2ind





最后出现64种DCM颜色(有点偏,可能是因为我的选择比较是错误的,但保证有64个单独的dcm颜色。)





我想你需要找到的是不同因素的正确加权(你可以加权函数)很容易进入 pdist2 。例如,将HSV加权为[0.8,0.1,0.1]给了我这种惊人的疯狂:




My girlfriend was saying that she may start doing some Cross Stitching and that she may want to make a drawing, image or whatever. In that moment I though "Well, I should be able to create a Matlab code to get any image and convert it to a cross-stitch patter". It turns out I am not the first one to think about this.

But Im not sure if I am doing the right thing.

So lets illustrate an example:

Suppose a pixelated image, any size, any color palette. for example the following screenshot from pixel artist WANEELLA

Suppose that we don't want to scale the image, the result image will have the same amount of pixels as the original (else a imresize will do).

Now the problem is using only the color palette from the available ones. I decided to use the DCM palette, mainly because I found the RGB conversion of it.

I created away of colour quantization. I use Lab colors to find the closest colour in the DCM palette and use that one.

clear;clc;
% read image (its a gif)
[img,C]=imread('wn.gif');
% Convert it to RGBimage.
img2=img(:,:,:,3);

imgC=zeros([size(img2) 3]);

for ii=1:size(img2,1)
    for jj=1:size(img2,2)
        imgC(ii,jj,:)=C(img2(ii,jj)+1,:);
    end
end
img=imgC;
imshow(img)

% read DCMtoRB conversion
fid=fopen('DCMRGB.txt');
fgets(fid);
ii=0;
tline = fgets(fid);
while ischar(tline)
    ii=ii+1;
    table{ii}=tline;
    tline = fgets(fid);
end
fclose(fid);

for ii=1:size(table,2)
   DCMRGB(ii,1)=str2num(table{ii}(1:4));
   DCMRGB(ii,4)=hex2dec(table{ii}(end-5:end-4));
   DCMRGB(ii,3)=hex2dec(table{ii}(end-7:end-6));
   DCMRGB(ii,2)=hex2dec(table{ii}(end-9:end-8));
end

% origColous=reshape(img, [], 3);
Colours=double(unique(reshape(img, [], 3), 'rows'));
Ncol=size(Colours,1);



cform = makecform('srgb2lab');
DCMLab = applycform(DCMRGB(:,2:4)./255,cform);
Colourslab = applycform(Colours,cform);


eudist=@(p)sqrt(p(:,1).^2+p(:,2).^2+p(:,3).^2);
Cind=zeros(Ncol,1);

for ii=1:Ncol
    aux=ones(size(DCMLab,1),3);
    aux(:,1)=Colourslab(ii,1);
    aux(:,2)=Colourslab(ii,2);
    aux(:,3)=Colourslab(ii,3);
    d=eudist(DCMLab-aux);
    [~,Cind(ii)]=min(d);
end
% now DCMRGB will have  DCMcode, R, G, B
% Perform map conversion
img2=zeros(size(img));
indimg=zeros(size(img,1),size(img,2));
for ii=1:size(img,1)
    for jj=1:size(img,2)
        %wich colour is the pixel?
        [~,indx]=ismember(double(squeeze(img(ii,jj,:)))',Colours,'rows'); 
        indimg(ii,jj)=Cind(indx);
        img2(ii,jj,:)=DCMRGB(Cind(indx),2:4);
    end
end


%%
subplot(121)
imshow((img))
% subplot(222)
% [X_dither,map]=rgb2ind(img,DCMRGB(:,2:4)./255,'nodither');
% imshow(uint16(X_dither),map);

subplot(122)
imshow(double(img2)./255)

The result looks like:

However, in this webpage : http://www.picturecraftwork.com/ As you can see, the choice of colours is different in the webpage, and actually it makes more sense and it gives a quite good feeling even without the real colormap.

After a lot of going around, I believe that there could be 2 main things I need to change and implement.

1.- I dont trust 100% the DCMRGB values. I emailed the company seeking more information about theyr color palette.

2.- The brigthness, contrast, hue and saturation values have enormous influence in the output.

how can I modify this 4 values (as in the webpage) in the desired image using Matlab?



DMC2RGB file: (I can copy paste it here if needed)

http://pastebin.com/qixUgnvy

DCM color pallete:

解决方案

Okay, here's a generalised suggestion, although I haven't managed to get great results with it yet.

1) Start by reducing your original image to a sensible number of colours using rgb2ind with nodither, specifying only the number of colors (not the map used).

[I_ind, old_map] = rgb2ind(I,64,'nodither);

You can experiment with the number of colours for a given image that fit without losing too much detail. Basically you want to figure out how many unique colours you want first (seeing as you're cross-stitching the output, you don't want a bunch of colors that only are used for about three stitches each).

2) Convert both maps (the one that's the output of rgb2ind and the one that you load from the dcm to rgb file) to an appropriate colour space (I used HSV because I was feeling lazy, L*a*b is probably better).

3) Select colours by checking which indexed colours have the most pixels present, picking the one that's closest, then removing that colour from the candidate list so we end up with the 64 or whatever

% use histogram and sorting - assign colours to most common values first
[plist pbins] = hist(I_ind(:),0:63);
[plist_sorted, sort_ind] = sort(plist, 'descend');

% old_map = the output of rbg2ind
% new_map = the new one we're about to make
% dcm_map = (copy of!) the dcm map in the same colorspace 
new_map = zeros(size(old_map)); 

% loop through from most to least common, remove a colour from the dcm map if we've used it.
for n = 1:sort_ind
   D = pdist2(old_map(n,:),dcm_map);
   m = find(D==min(D),1,'first');
   new_map(n,:) = dcm_map(m,:);
   dcm_map(m,:) = [];
end

I used the image you used to have up on the question. As it comes out of rgb2ind:

As it comes out at the end with 64 DCM colors (a bit off, probably because my choice of comparison is wrong, but guaranteed to have 64 separate dcm colors).

I guess what you need to find is the right weighting of the different factors (you can put a weighting function into pdist2 quite easily). For example, weighting HSV as [0.8, 0.1, 0.1] gave me this brilliant madness:

这篇关于十字绣到Matlab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆