39039

Replace defined colors of a source image with a background image

Question:

I need to write a function that takes 4 parameters: to change the blue background of an image and replace it with other image

Answer1:

function bluescreen(A,B,c,thresh) A = imread(A); B = imread(B); Ar = A(:,:,1); Ag = A(:,:,2); Ab = A(:,:,3); Br = B(:,:,1); Bg = B(:,:,2); Bb = B(:,:,3); logmap = zeros([size(A,1),size(A,2)]); logmap = (Ar > (c(1)-thresh)).*(Ar < (c(1)+thresh)).*... (Ag > (c(2)-thresh)).*(Ag < (c(2)+thresh)).*... (Ab > (c(3)-thresh)).*(Ab < (c(3)+thresh)); Ar(logmap == 1) = Br(logmap == 1); Ag(logmap == 1) = Bg(logmap == 1); Ab(logmap == 1) = Bb(logmap == 1); A = cat(3 ,Ar,Ag,Ab); imshow(A); end

When you call it like, bluescreen('peppers.png','tape.png',[200 10 10],50);

It gives you,

<img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/X3DdO.jpg" data-original="https://i.stack.imgur.com/X3DdO.jpg" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" />

I'm not sure what you want!

Ok. I cut both images and called bluescreen('A.png','B.png',[30 30 120],80);

I get this,

<img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/Rx8Ke.jpg" data-original="https://i.stack.imgur.com/Rx8Ke.jpg" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" />

I think It is good enough, don't you?!

Recommend

  • Get x intercept given data points in R
  • DrawContours() not working opencv python
  • MDX Get UserName Where UserID
  • ag-grid column headers stacked to the left
  • trigger.io - Can't create ipa-file anymore
  • Tensorflow neural network prediction is always the same
  • Updating Ui Components in Activity based on MediaPlayer object from Service While Playing music file
  • exceptions.TypeError: src is not a numpy array, neither a scalar
  • Open source augmented reality framework for BlackBerry
  • Image change opacity on hover without jQuery
  • Building libiconv fails with the Android standalone toolchain
  • Skewing an array in Python
  • How to use OpenCV in python 3.4 on windows 7 x64? [duplicate]
  • Initialize specific subscript item in array by c++ [duplicate]
  • Trying to find the last non-empty cell in a specific row/range over multiple sheets
  • SQL Server - Get all children of a row in many-to-many relationship?
  • Problems using HOGDescriptor
  • Does Perl currently (5.8 and 5.10) make any promises about the order alternations will be used?
  • Automatically change the position of objects when using different devices
  • Regex: Match everything except backreference
  • K-means in OpenCV's Python interface
  • Zend Framework 2, Module Redirect
  • Why does PHP appear to evaluate this condition incorrectly?
  • How does extglob work with shell parameter expansion?
  • C - formatting MAC address
  • Contact form problem - I do receive messages, but no contents (blank page)
  • Google analytics measurement protocol session timeout and query time limits
  • Python/Javascript: WYSIWYG html editor - Handle large documents fast and/or design theory
  • Streaming screenshots over WebRTC as a video stream from iOS
  • Is there a package like bigmemory in R that can deal with large list objects?
  • How to estimate the Kalman Filter with 'KFAS' R package, with an AR(1) transition equation
  • Azure webjobs output logs indexing taking very long
  • SAXReader not re-ecape characters
  • ADO and msqli connections very slow
  • Marklogic : Query response time is very high
  • How to use remove-erase idiom for removing empty vectors in a vector?
  • Checking free space on FTP server
  • R: gsub and capture
  • AT Commands to Send SMS not working in Windows 8.1
  • To Get the radio button value in ruby on rails