How get the difference between 2 BMP files using vbscript? - vbscript

I'm trying to compare between 2 bmp files looks the same but with Mercury.FileCompare the result return false.
i want to get the difference in precentege? any suggest?
Maybe some way to take bitmap and draw the image as array of number between 0-255?
Thanks

You can still use the old way to compare bitmaps
Set objMercuryFilecompare = CreateObject("Mercury.FileCompare")
If objMercuryFilecompare.IsEqualBin("C:\Users\pankaj.jaju\Desktop\test1.bmp" , "C:\Users\pankaj.jaju\Desktop\test2.bmp",0,1) Then
msgbox "match"
else
msgbox "mismatch"
end if
Set objMercuryFilecompare = nothing

Related

Writing Macro in ImageJ to open, change color, adjust brightness and resave microscope images

I'm trying to write a code in Image J that will:
Open all images in separate windows that contains "488" within a folder
Use look up tables to convert images to green and RGB color From ImageJ, the commands are: run("Green"); and run("RGB Color");
Adjust the brightness and contrast with defined values for Min and Max (same values for each image).
I know that the code for that is:
//run("Brightness/Contrast..."); setMinAndMax(value min, value max); run("Apply LUT");
Save each image in the same, original folder , in Tiff and with the same name but finishing with "processed".
I have no experience with Java and am very bad with coding. I tried to piece something together using code I found on stackoverflow and on the ImageJ website, but kept getting error codes. Any help is much appreciated!
I don't know if you still need it, but here is an example.
output_dir = "C:/Users/test/"
input_dir = "C:/Users/test/"
list = getFileList(input_dir);
listlength = list.length;
setBatchMode(true);
for (z = 0; z < listlength; z++){
if(endsWith(list[z], 'tif')==true ){
if(list[z].contains("488")){
title = list[z];
end = lengthOf(title)-4;
out_path = output_dir + substring(title,0,end) + "_processed.tif";
open(input_dir + title);
//add all the functions you want
run("Brightness/Contrast...");
setMinAndMax(1, 15);
run("Apply LUT");
saveAs("tif", "" + out_path + "");
close();
};
run("Close All");
}
}
setBatchMode(false);
I think it contains all the things you need. It opens all the images (in specific folder) that ends with tif and contains 488. I didn't completely understand what you want to do with each photo, so I just added your functions. But you probably won't have problems with adding more/different since you can get them with macro recorder.
And the code is written to open tif files. If you have tiff just be cerful that you change that and also change -4 to -5.

send image behind text word using VBS

i'm using VBS to create a title screen and i have a problem trying to send a image behind te text.
Here is my code:
function page()
Set oWord = CreateObject("Word.Application")
oWord.Visible = True
Set objDoc = oWord.Documents.Open("C:\xxx.docx")
objDoc.Sections.PageSetup.DifferentFirstPageHeaderFooter = true
Set head = objDoc.Shapes.AddPicture("C:\img.png")
head.PictureFormat.Brightness = 0.7
head.ZOrder msoSendBehindText 'I try to use msoSendToBack, SendBack, SendBehindText, Back and others and not work
end function
i just want send "head" to the back , the actual result is the image is not in the back of text, and the version of word is 2013.
If someone, know how to solve this, thanks in advance.
The solution was, the utilization of numeration
head.ZOrder 5
https://bettersolutions.com/vba/enumerations/msozordercmd.htm
with this change, i solve my problem.

VB6 - Load/store images to be used later

I have an image control on my form and I want the picture to change based on certain events. Let's say there are four different possible images. I know that I can set the control to whatever image I want using:
imgBox1.Picture = LoadPicture(sPath & "img1.bmp")
But I guess my question really is, do I have to use the LoadPicture function every time I want to change imgBox1 to a different picture (say, "img2.bmp")? Or can I load the four different images to some kind of object and then just set imgBox1.Picture to equal that object? I've tried several different ways and can't get anything to work.
StdPicture is the type to use to store an image.
The example below loads 3 images from disk once then cycles them on a button click.
Private mPics(2) As StdPicture
Private mIndex As Long
Private Sub Form_Load()
Set mPics(0) = LoadPicture("C:\kitty_born.bmp")
Set mPics(1) = LoadPicture("C:\kitty_life.bmp")
Set mPics(2) = LoadPicture("C:\kitty_dead.bmp")
End Sub
Private Sub someButton_Click()
If mIndex > UBound(mPics) Then mIndex = 0
Set somePictureOrImageBox.Picture = mPics(mIndex)
mIndex = (mIndex + 1)
End Sub
You could create a control array of Image/PictureBox controls, each holding one of the several images, and set their visibility depending on the image you want displayed at a time.
Alternativley, you could have a hidden control array of PictureBoxs and then use the PaintPicture method of the PictureBox you wish to change to paste in the desired image.

How to insert and resize an image in Word?

I have written a VBScript to automate the creation of a Word document.
I'm using the following code to insert an image, but I can't seem to find a way to then resize it.
objSelection.InlineShapes.AddPicture("C:\test.jpg")
The AddPicture method returns a handle to the inserted object, so you could do something like this:
Set pic = objSelection.InlineShapes.AddPicture("C:\test.jpg")
pic.Height = 100
pic.Width = 200

Making a gif from images

I have a load of data in 100 .sdf files (labelled 0000.sdf to 0099.sdf), each of which contain a still image, and I'm trying to produce a .gif from these images.
The code I use to plot the figure are (in the same directory as the sdf files):
q = GetDataSDF('0000.sdf');
imagesc(q.data');
I've attempted to write a for loop that would plot the figure and then save it with the same filename as the sdf file but to no avail, using:
for a = 1:100
q=GetDataSDF('0000.sdf');
fh = imagesc(q.dist_fn.x_px.Left.data');
frm = getframe( fh );
% save as png image
saveas(fh, 'current_frame_%02d.jpg');
end
EDIT: I received the following errors when trying to run this code:
Error using hg.image/get
The name 'Units' is not an accessible property for an instance of class 'image'.
Error in getframe>Local_getRectanglesOfInterest (line 138)
if ~strcmpi(get(h, 'Units'), 'Pixels')
Error in getframe (line 56)
[offsetRect, absoluteRect, figPos, figOuterPos] = ...
Error in loop_code (line 4)
frm = getframe( fh );
How do I save these files using a for loop, and how do I then use those files to produce a movie?
The reason for the error is that you pass an image handle to getframe, but this function excpects a figure handle.
Another problem is that you always load the same file, and that you saveas will not work for gifs. (For saving figures as static images, maybe print is the better option?)
I tried to modify my own gif-writing loop so that it works with your data. I'll try to be extra explicit in the comments, since you seem to be starting out. Remember, you can always use help name_of_command to display a short Matlab help.
% Define a variable that holds the frames per second your "movie" should have
gif_fps = 24;
% Define string variable that holds the filename of your movie
video_filename = 'video.gif';
% Create figure 1, store the handle in a variable, you'll need it later
fh = figure(1);
for a = 0:99
% Prepare file name so that you loop over the data
q = GetDataSDF(['00' num2str(a,'%02d') 'sdf']);
% Plot image
imagesc(q.dist_fn.x_px.Left.data');
% Force Matlab to actually do the plot (it sometimes gets lazy in loops)
drawnow;
% Take a "screenshot" of the figure fh
frame = getframe(fh);
% Turn screenshot into image
im = frame2im(frame);
% Turn image into indexed image (the gif format needs this)
[imind,cm] = rgb2ind(im,256);
% If first loop iteration: Create the file, else append to it
if a == 0;
imwrite(imind,cm,video_filename,'gif', 'Loopcount',inf);
else
imwrite(imind,cm,video_filename,'gif','WriteMode','append','DelayTime',1/gif_fps);
end
end
One more note: When the size of the data is the same for each plot, it makes sense to only use the plot(or in this case, imagesc) command once, and in later loop iterations replace it with a set(ah,'Ydata',new_y_data) (or in this case set(ah,'CData',q.dist_fn.x_px.Left.data'), where ah is a handle of the plot axes (not the plot figure!). This is orders of magnitude faster than creating a whole new plot in each loop iteration. The downside is that the scaling (here, the color-scaling) will be the same for each plot. But in every case that I have worked on so far, that was actually desirable.

Resources