Facebook
From Colorant Zebra, 9 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 720
  1. %% Test out the possibily of creating color gaussians that will be applied
  2. % on inpout image. Color is class-dependent and intensity length-dependent.
  3. % white - white space
  4. % black - text
  5. % red - stamps
  6. % green - tables
  7. % blue - signatures
  8. % Also - the window width and height is equal to average w&h from database
  9.  
  10. clc
  11. close all
  12. clear all
  13.  
  14. % load image
  15. input.image = im2double(imread('../database/signed_docs/10.jpg'));
  16. [input.w, input.h, ~] = size(input.image);
  17.  
  18. % window size
  19. window.w = 100;
  20. window.h = 100;
  21.  
  22. % step == half of window's size?
  23. step.w = window.w / 2;
  24. step.h = window.h / 2;
  25.  
  26. % std
  27. sigma = 25;
  28.  
  29. % create gaussian mask
  30. mask.gs = fspecial('gaussian', [window.h window.w], sigma);
  31. mask.gs = mask.gs ./ max(mask.gs(:));
  32.  
  33. % create color masks
  34. mask.white = ones(window.h, window.w, 3);
  35. mask.black = zeros(window.h, window.w, 3);
  36. mask.red = cat(3, ones(window.h, window.w), zeros(window.h, window.w),...
  37.     zeros(window.h, window.w));
  38. mask.green = cat(3, zeros(window.h, window.w), ones(window.h, window.w),...
  39.     zeros(window.h, window.w));
  40. mask.blue = cat(3, zeros(window.h, window.w), zeros(window.h, window.w),...
  41.     ones(window.h, window.w));
  42.  
  43. fn = fieldnames(mask);
  44.  
  45. %loop through image and apply mask randomly
  46. for i = 1 : step.h : input.h - window.h-step.h
  47.     for j = 1 : step.w : input.w - window.w-step.w
  48.        
  49.         % extract part of the image
  50.         window.current = input.image(i : i + window.h - 1, j : j + window.w - 1, :);
  51.        
  52.         % apply mask randomly
  53.         color = round(rand(1) * 5) + 1;
  54.         mask.current = mask.(fn{color});
  55.        
  56.         % apply
  57.        
  58.        
  59.     end
  60. end
  61.  
  62.