Replace image in a shape, not add a new one - vb.net

I have a VSTO written in VB.NET and want to maximize a selected image to the background. Documents tell me to remove the old shape and add a new one with AddPicture, but I have a template that includes image shapes already there and AddPicture puts the image in one of those shapes already there.
To prevent images from landing in the wrong shape I really just want to replace the original image with the resized one.
This is what I have:
dim src as PowerPoint.Shape = PowerPoint.Selection.ShapeRange.Item(1)
src.Export(file1, PowerPoint.PpShapeFormat.ppShapeFormatPNG)
dim img as Image = BitMap.FromFile(file1)
Then some image magic, and then:
img.Save(file2, PowerPoint.PpShapeFormat.ppShapeFormatPNG)
Dim _S As PowerPoint.Slide = ppApp.ActiveWindow.View.Slide
Dim _P As PowerPoint.Shape = _S.Shapes.AddPicture2(file2, MsoTriState.msoFalse, MsoTriState.msoTrue, 0, 0, _W, _H)
But that puts the image in the wrong template-shape.
Is there a way to actually replace the image in a shape without adding a new shape?

You can't insert an image inside a shape, only (in some cases) inside a placeholder, and you've mentioned that you specifically don't want to do that.
You can use an image to fill a shape, but unless you don't mind the image getting distorted, the aspect ratios of the image and the shape must match.
Suggestion: before adding the new image/shape, iterate through all the shapes on the slide looking for placeholder shapes. If any placeholder shape is of a type that can contain images (Content, Picture and Clip Art placeholders), fill it with dummy content (a few characters of text for Content, any random picture for the other two). Add your image; since the "image-capable" placeholders are already filled, the image will be added as a new shape. Then delete each of the shapes you've added dummy content to. When you delete a placeholder that has content, the content gets deleted and leaves the original empty placeholder behind.

Related

how to add random values (random number to specific spot ) to x-ray image with tensorflow

I want to predict disease and I want to try to make the image have some noise or disruption in specific spot or randomly spot is there any method or solution for it??
is there any way to add noise (random value) to image with tensorflow
I read the image and convert it to array and make a copy of it and then add to it some number is that right??
and i have noticed that when convert it the array became values of zeros and ones even it in rgb form.
i expect the some value in the array or the value in the image change to another values so when imshow (the image) notice some noise (different from guassian noise) so when the input to the model become different from the original image
I have trying this but operand didn't match between(224,224,3) and (224,224)
but when set colormode to grayscal the operand work but i didnt see that much of change in image.
,when trying replace img.size with img.height did'nt work either
img = tf.keras.preprocessing.image.load_img("/content/person1_bacteria_2.jpeg",color_mode="rgb",target_size=(256, 256))
nois_factor = 0.3
n = nois_factor * np.random.randn(*img.size)
noise_image = img + n
plt.imshow(noise_image)

Get the location of object to crop by providing pixel label in tensorflow

I have a data-set of images(every image is in rgb format) and corresponding label image(which contains label of every pixel in the image).
I need to extract the objects(pixels) of a particular class from original images.
first i have to find location of object using label image(by providing label of given object)(it is doable by using explicit for loops but, i don't want to use explicit for loops)
Now my questions-
If there is any in-build function in tensorflow that gives me the location(Rectangles are fine) of given object(if i provide the labels of that object)?
After that i can use the tf.image.crop_and_resize to crop the image. but i am not able to find any function that will give me location of objects.

Accessing pixel values from destination image of CopyMakeBorder function in Emgu CV

A little bit new to EmguCV here
Just want to ask quick question, about CopyMakeBorder function
Are the pixel values of the destination image accessible?
I want to process further the destination image, but when I tried to access pixel values from the image, it only returns me 0 (even in the location that are not supposed to be 0, for example the central pixel). When I used Imshow, it shows that the image borders are perfectly processed, but problem only persist when I try to access the pixel values, only getting 0 wherever the pixel location is.
This is not a problem when I tried to use destination images from other EmguCV functions, such as Threshold Function
Can anyone clarify? Thanks A lot!!
I am using VB.net, here is the code (I am away from my workstation for the weekend so I am just gonna try to remember the code, probably some capital letters here and there are mistyped, but I hope you get the gist.)
First I initialize the source images and destination image
Dim img As Image(Of Gray,Byte) = New Image (Of Gray, Byte)("myimage.jpg")
Dim img1 As Image(Of Gray,Byte) = New Image (Of Gray, Byte)(img.size)
CopyMakeBorder Function, extend 1 pixel to top, bottom, left and right. Border type constant 0 values
Cvinvoke.CopyMakeBorder(img,img1,1,1,1,1,BorderType.Constant, New MCvscalar(0))
Accessing pixel values from destination image, take example pixel in x = 100, y = 100, and channel 0 (as it is a grayscale image)
Console.writeline(img1.data(100,100,0))
This will make debug output to 0, and no matter where I try to take the pixel values, it is still 0, even though when I try to show the image that specific pixel should not be 0 (it is not black)
Cvinvoke.Imshow("test",img1)
You are trying to access the data through Image.Data, however, this doesn't include the added border(s); just the original bitmap.
The added border is in the Mat property, however. Through it the individual pixels can be accessed
' returns data from original bitmap
Console.WriteLine(img1.Data(100, 100, 0))
' returns data from modified bitmap
Console.WriteLine(img1.Mat.GetData(100, 100)(0))

How can I crop by x,y,width,height all images in a folder, resize them, then save them?

I am new to Photoshop scripting, but no stranger to Javascript.
I have a folder of images of 1024*1024 that are frames of an animation in a 3d program.
There is only an area at x=54, y=12, width=300, height=234 for all the frames.
After the crop I would like them to be scaled at 65% or whatever I want.
Alternatively I would like the source image to be scaled, the image moved x / y coordinates at 65% reduction so that the outside pixels don't make it in the final product.
There are no psds to speak of, I assume the script would create a blank psd and most likely have it recycled for the batch crop/resize.
Try something along these lines for the cropping and resizing. You can also copy all the images into a single PSD before you save if that is what you're after, but this sample just saves over the original document. For more info check out your Photoshop JavaScript Reference pdf in your Photoshop install directory.
var dir = new Folder('/c/temp')
var files = dir.getFiles("*.psd"); //change for whatever file type you have
for (var i = 0; i < files.length; i++) {
var doc = app.open(files[i]);
var bounds = [54, 12, 354, 246];
doc.crop(bounds);
//do the math to figure out how big you want it after resize
doc.resizeImage(newWidth, newHeight);
//note this is saving over the original!!!!
doc.close(SaveOptions.SAVECHANGES)
}
why not just record the action in photoshop???
open the first file and create a new action.
proceed to trim the canvas as needed with either the crop tool or canvas resize.
run the action as a batch process on the folder as needed.

Capture which shape was clicked on in powerpoint

I have a PowerPoint presentation in which some slides contain multiple shapes for the user to click on.
I want to capture which shape is clicked. I am able to capture if shape has test on it using macro but what if it shape contains any image?
Every shape on a slide has a unique ID property that you can examine to determine which shape is selected.
Or you can add a tag to the shape beforehand:
ActiveWindow.Selection.ShapeRange(1).Tags.Add "MyName", "MyValue"
then
If ActiveWindow.Selection.ShapeRange(1).Tags("MyName") = "MyValue" Then
' Whatever